Suggesting a correct query
It's very common for users to commit typing errors or to require suggestions for the words they are writing. These issues are solved by ElasticSearch with the suggest functionality.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script chapter_05/populate_query.sh
, available in the code bundle for this book.
How to do it...
In order to suggest relevant terms by query, perform the following steps:
From the command line, execute a
suggest
call:curl -XGET 'http://127.0.0.1:9200/test-index/_suggest?pretty=true' -d ' { "suggest1" : { "text" : "we find tester", "term" : { "field" : "parsedtext" } } }'
This result will be returned by ElasticSearch if everything works all right:
{ "_shards": { "failed": 0, "successful": 5, "total": 5 }, "suggest1": [ { "length": 2, "offset": 0, "options": [], "text": "we" }, { "length": 4, "offset": 3, ...