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