嵌套内部命中的弹性搜索聚合
我在Elasticsearch中获得了大量数据.我的douments有一个名为“records”的嵌套字段,其中包含具有多个字段的对象列表.
我希望能够从记录列表中查询特定对象,因此我在查询中使用inner_hits字段,但它没有帮助,因为聚合使用大小0,因此不返回任何结果. 我没有成功只为inner_hits进行聚合工作,因为聚合会返回记录中所有对象的结果,无论查询是什么. 这是我正在使用的查询: curl -XPOST 'localhost:9200/_msearch?pretty' -H 'Content-Type: application/json' -d' { "index":[ "my_index" ],"search_type":"count","ignore_unavailable":true } { "size":0,"query":{ "filtered":{ "query":{ "nested":{ "path":"records","query":{ "term":{ "records.data.field1":"value1" } },"inner_hits":{} } },"filter":{ "bool":{ "must":[ { "range":{ "first_timestamp":{ "gte":1504548296273,"lte":1504549196273,"format":"epoch_millis" } } } ],} } } },"aggs":{ "nested_2":{ "nested":{ "path":"records" },"aggs":{ "2":{ "date_histogram":{ "field":"records.timestamp","interval":"1s","min_doc_count":1,"extended_bounds":{ "min":1504548296273,"max":1504549196273 } } } } } } }'
您的查询非常复杂.
简而言之,这是您要求的查询: { "size": 0,"aggregations": { "nested_A": { "nested": { "path": "records" },"aggregations": { "bool_aggregation_A": { "filter": { "bool": { "must": [ { "term": { "records.data.field1": "value1" } } ] } },"aggregations": { "reverse_aggregation": { "reverse_nested": {},"aggregations": { "bool_aggregation_B": { "filter": { "bool": { "must": [ { "range": { "first_timestamp": { "gte": 1504548296273,"lte": 1504549196273,"format": "epoch_millis" } } } ] } },"aggregations": { "nested_B": { "nested": { "path": "records" },"aggregations": { "my_histogram": { "date_histogram": { "field": "records.timestamp","interval": "1s","min_doc_count": 1,"extended_bounds": { "min": 1504548296273,"max": 1504549196273 } } } } } } } } } } } } } } } 现在,让我用聚合的名称解释每一步: > size:0 – >我们对点击不感兴趣,只对汇总感兴趣> nested_A – > data.field1正在记录中,因此我们将范围转移到记录中> bool_aggregation_A – >按data.field1过滤:value1> reverse_aggregation – > first_timestamp不在嵌套文档中,我们需要从记录中查看范围> bool_aggregation_B – >按first_timestamp范围过滤> nested_B – >现在,我们再次将范围放入时间戳字段的记录中(位于记录下)> my_histogram – >最后,按时间戳字段汇总日期直方图 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |