Search code examples
elasticsearchfacet

ElasticSearch terms_stats query - exclude terms from result


I currently have a terms facet that excludes certain terms from its results, using the exclude option. I tried the same with a term_stats facet but the same results are not dropped.

I have looked at the Elasticsearch documentation (http://www.elasticsearch.org/guide/reference/api/search/facets/terms-stats-facet/) and see that the term_stats facet doesn't appear to have an exclude option. Since I don't always trust my full interpretation of the elasticsearch docs I was looking to see if anybody had found a workaround (beyond processing out the results client-side).

This facet doesn't work as expected:

"keywords_bad":{
  "terms_stats":{
    "size":100,
    "value_field":"retweet_count",
    "exclude":["http","consected"],
    "order":"total",
    "key_field":"text"
  }
}

whereas this facet works as expected:

"keywords_good":{    
  "terms":{
    "size":100,
    "exclude":["http","consected"],
    "order":"count",
    "field":"text"
  }
}

Any reasonable suggestions would be appreciated, as this seems a little inconsistent.

UPDATE

Based on the accepted answer by imotov, I created an issue on GitHub at https://github.com/elasticsearch/elasticsearch/issues/2916


Solution

  • terms_stats facet doesn't support exclude at the moment. I would suggest creating an issue on github asking for it to be added.