我们终于解决了我们的问题。
我们的解决方案是(如我们预期的那样)一个预先计算的
people_all字段。但是在导入数据时,我们正在编写其他字段,而不是使用
copy_toor
transform而是在编写它。该字段如下所示:
"people": { "type": "nested", .. "properties": { "firstName": { "type": "string", "store": "yes", "index": "not_analyzed" }, "lastName": { "type": "string", "store": "yes", "index": "not_analyzed" }, "people_all": { "type": "string", "index": "not_analyzed" } }}请
"index":"not_analyzed"在
people_all现场注意。这对于拥有完整的存储桶很重要。如果您不使用它,我们的示例将返回3个存储桶“ john”,“
jane”和“ doe”。
编写完这个新字段后,我们可以进行如下操作:
{ "size": 0, "query": { "term": { "street": "Baker Street" } }, "aggs": { "people_distinct": { "nested": { "path": "people" }, "aggs": { "people_all_distinct": { "terms": { "field": "people.people_all", "size": 0 } } } } }}我们返回以下响应:
{ "took": 2, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 0.0, "hits": [] }, "aggregations": { "people_distinct": { "doc_count": 3, "people_name_distinct": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "John Doe", "doc_count": 2 }, { "key": "Jane Doe", "doc_count": 1 } ] } } }}现在,在响应中,我们可以创建不同的人员对象。
请让我们知道是否有更好的方法来实现我们的目标。
解析存储桶不是最佳解决方案,
firstName并且
lastName在每个存储桶中都包含字段会更加有趣。



