2

I have a field that contains comma separated values which I want to perform suggestion on.

 {
    "description" : "Breakfast,Sandwich,Maker"
 }

Is it possible to get only applicable token while performing suggest as you type?? For ex: When I say break, how can I get only Breakfast and not get Breakfast,Sandwich,Maker?

I have tried using commatokenizer but it seems it does not help

victorkt
  • 13,992
  • 9
  • 52
  • 51

1 Answers1

1

As said in the documentation, you can provide multiple possible inputs by indexing like this:

curl -X PUT 'localhost:9200/music/song/1?refresh=true' -d '{
    "description" : "Breakfast,Sandwich,Maker",
        "suggest" : {
            "input": [ "Breakfast", "Sandwitch", "Maker" ],
            "output": "Breakfast,Sandwich,Maker"
    }
}'

This way, you suggest with any word of the list as input.

Obtaining the corresponding word as suggestion from Elasticsearch is not possible but as a workaround you could use a tokenizer outside Elasticsearch to split the suggested string and choose only the one that has the input as prefix.

EDIT: a better solution would be to use an array instead of comma-separated values, but it doesn't meet your specs... ( look at this: Elasticsearch autocomplete search on array field )

Community
  • 1
  • 1
Heschoon
  • 2,915
  • 9
  • 26
  • 55
  • As a workaround, is it possible to perform suggest across multiple fields?? – Viola Pinto May 05 '15 at 06:56
  • You can use multiple suggesters then, one on each field. If you can modify your specifications, you can also simple make suggestions on an array as shown in my edit (instead of a string with comma-separated values) – Heschoon May 05 '15 at 10:48