您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Elasticsearch:聚合,按字段计数

Elasticsearch:聚合,按字段计数

您需要在not_analyzed您的location字段中添加一个子字段。

首先像这样修改您的映射:

curl -XPOST 'http://localhost:9200/testing/_mapping/external' -d '{
   "properties": {
      "location": {
         "type": "string",
         "fields": {
            "raw": {
               "type": "string",
               "index": "not_analyzed"
            }
         }
      }
   }
}'

然后再次为您的数据重新编制索引:

curl -s -XPOST 'http://localhost:9200/testing/external/_bulk?pretty' --data-binary @bulk.json

最后,您将能够像这样(在location.raw字段上)运行查询并获得您期望的结果:

curl -s -XPOST 'localhost:9200/testing/_search?pretty' -d '
{
  "aggs": {  "location_count": { "terms": { "field":"location.raw",   "size":100 }}}
}' | jq  '.aggregations'
其他 2022/1/1 18:22:24 有444人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶