Does anyone know how to add filter to suggester?
This works very well:
{ "headline-suggest" : { "text" : "n", "completion" : { "field" : "headline_suggest" } }
but I want force ElasticSearch to build list of suggestions from subset of data, like:
{ "headline-suggest" : { "text" : "n", "completion" : { "field" : "headline_suggest" } }, "filter" : { "term" : { "mydifferentfield" : "someword" } } }
How can I achieve it?
(I'm using elasticsearch 0.90.5)
Autocomplete can be achieved by changing match queries to prefix queries. While match queries work on token (indexed) to token (search query tokens) match, prefix queries (as their name suggests) match all the tokens starting with search tokens, hence the number of documents (results) matched is high.
The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. The suggested terms are provided per analyzed suggest text token. The term suggester doesn't take the query into account that is part of request.
Frequently used filters will be cached automatically by Elasticsearch, to speed up performance. Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.
As per version 1.2.0, you can add context to your suggester and obtain filtered suggestions.
Introductory blog post Introductory blog post
Full Docs Full Docs
i am not really sure about that, but i think that you can not filter a suggest request in elasticsearch.
from what i read this is due to the kind of data structure it is stored in. elasticsearch calculates statistical data on the terms to suggest at index time and uses those for the suggest operations.
did you try performing a normal query in combination with a suggest? maybe there is a different outcome to that?
curl -s -XPOST 'localhost:9200/_search' -d '{ "query" : { ... }, "suggest" : { ... } }'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With