ElasticSearch整个字段聚合 [英] ElasticSearch terms aggregation by entire field

查看:255
本文介绍了ElasticSearch整个字段聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个考虑整个字段值而不是单个令牌的ElasticSearch术语聚合查询?例如,我想按城市名称聚合,但以下返回 york san francisco 作为单独的桶,而不是纽约 san francisco 作为预期的桶。

  curl -XPOSThttp:// localhost :9200 / cities / _search-d'
{
size:0,
aggs:{
cities:{
:{
field:city,
min_doc_count:10
}
}
}
}'


解决方案

您应该在映射中解决这个问题。添加not_analyzed字段。您可以创建多个字段,如果您还需要分析的版本。

 相册:{
city :string,
fields:{
raw:{
type:string,
index:not_analyzed
}
}
}

现在在city.raw上创建你的汇总p>

How can I write an ElasticSearch term aggregation query that takes into account the entire field value, rather than individual tokens? For example, I would like to aggregate by city name, but the following returns new, york, san and francisco as individual buckets, not new york and san francisco as the buckets as expected.

curl -XPOST "http://localhost:9200/cities/_search" -d'
{
   "size": 0, 
   "aggs" : {
     "cities" : {
         "terms" : { 
            "field" : "city",
            "min_doc_count": 10
         }
     }
   }
}'

解决方案

You should fix this in your mapping. Add a not_analyzed field. You can create the multi field if you also need the analyzed version.

"album": {
  "city": "string",
  "fields": {
    "raw": {
      "type": "string",
      "index": "not_analyzed"
    }
  }
}

Now create your aggregate on city.raw

这篇关于ElasticSearch整个字段聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆