字符串字段如何包含在结果集中 聚合 </跨度> ?例如,给出以下映射:
{ “sport”:{ “映射”:{ “跑步者”:{ “属性 ” }, “sport”:{ “type”:“string” } } } } } }
样品 数据 </跨度> :
curl -XPOST“http:// localhost:9200 / sport / _bulk”-d’ {“指数
如果我正确地理解你,这似乎就是你想要的:
POST /sport/_search { "size": 0, "aggregations": { "city_terms": { "terms": { "field": "city" }, "aggs": { "name_terms": { "terms": { "field": "name" } } } } } }
使用您提供的数据,它将返回:
{ "took": 43, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 3, "max_score": 0, "hits": [] }, "aggregations": { "city_terms": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "new", "doc_count": 2, "name_terms": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "bob", "doc_count": 1 }, { "key": "gary", "doc_count": 1 } ] } }, { "key": "york", "doc_count": 2, "name_terms": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "bob", "doc_count": 1 }, { "key": "gary", "doc_count": 1 } ] } }, { "key": "atlanta", "doc_count": 1, "name_terms": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "mike", "doc_count": 1 } ] } } ] } } }
(您可能想要添加 "index":"not_analyzed" 如果这些结果不符合您的预期,则映射到映射中的一个或两个字段。)
"index":"not_analyzed"
这是我用来测试它的代码:
http://sense.qbox.io/gist/07735aadc082c1c60409931c279f3fd85a340dbb