Elasticsearch multiple fields autosuggestion
How do I give autosuggestion to the user based on the matching field?
When user types 123, store it in a Java variable, prepare a query like below inserting that variable into and send a request to ElasticSearch.
{ "query" : { "query_string" : { "query" : "*123*" } }}
The above query will manage to check it in both fields mobileNo
and alternativeMobileNo
.
Similarly, if user types Rak, the query will be similar to the previous one,
{ "query" : { "query_string" : { "query" : "*Rak*" } }}
And I think you want to use highlighter api to answer your last how questions, which allows to highlight search results on one or more fields.
A screenshot of highlight example in es :