ElasticSearch terms aggregation on tokenized field

孤街醉人 提交于 2019-12-10 23:58:32

问题


when i do terms aggregation on string field (with whitespace tokenizer) i have results for each word (token), but i need results for whole strings. How can i do aggregation on string field like terms but group output by whole string, not by tokens?

I already saw this solutions: ElasticSearch term aggregation Terms aggregation based on unique key but they are based on keyword tokenizer

I can't use keyword tokenizer, because of i wan't apply stopwords filter while indexing


回答1:


I just had the same problem, and came here looking for a solution.

And then it dawned on me. there's a .raw (unanalyzed) field, and it worked. The solution was to use it.

So the aggregation went from:

{
  "aggs": {
    "keys": {
      "terms": {
        "size": 0,
        "field": "key"
}}}}}

to:

{
  "aggs": {
    "keys": {
      "terms": {
        "size": 0,
        "field": "key.raw"
}}}}}


来源:https://stackoverflow.com/questions/27815875/elasticsearch-terms-aggregation-on-tokenized-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!