您需要在
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'


