If we would like to find documents that have directors starting with tar
, we would run the following command:
curl -XGET localhost:9200/imdb/_suggest?pretty -d '{ "directorAutocomplete": { "text": "tar", "completion": { "field": "completion_suggest" } } }'
The result returned by Elasticsearch for the preceding query looks as follows:
{ "_shards": { "total": 5, "successful": 5, "failed": 0 }, "directorAutocomplete": [ { "text": "tar", "offset": 0, "length": 3, "options": [ { "text": "Andrei Arsenyevich Tarkovsky", "score": 1, "payload": { "movies": [ "Ivan's Childhood", "Andrei Rublev", "Solaris", "The Mirror", "Stalker", "Nostalgia", "The Sacrifice" ] } } ] } ] }
As you can see, the document about Andrei Tarkovsky has been returned to us with the payload information about his movies when we search for the phrase tar
because we indexed the phrases andrei
, arsenyevich
, and tarkovsky
in the document's completion field as input values. This is why the phrase tar
matched the phrase tarkovsky
and the text (that is, Andrei Tarkovsky Arsenyevich
) that is indexed as the output value is returned to us with the payload
field.
18.225.95.216