28

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)

1
  • Can you post your solution or accept a answer? Dec 3, 2016 at 8:07

3 Answers 3

23

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

1

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" : {
    ...
  }
}'
3
0

There is no way to filter on your completion. As javanna said, Completion feature is built on FST at indexing time, so you couldn't use filter here.

To do it, you could play around with ngram/edge ngram. Let read here to get basic idea: http://jontai.me/blog/2013/02/adding-autocomplete-to-an-elasticsearch-search-application/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.