我在Elasticsearch中获得了大量数据.我的douments有一个名为"records"的嵌套字段,其中包含具有多个字段的对象列表.
我希望能够从记录列表中查询特定对象,因此我在查询中使用inner_hits字段,但它没有帮助,因为聚合使用大小0,因此不返回任何结果.
我没有成功只为inner_hits进行聚合工作,因为聚合会返回记录中所有对象的结果,无论查询是什么.
这是我正在使用的查询:(每个文档都有first_timestamp和last_timestamp字段,记录列表中的每个对象都有一个时间戳字段)
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
}
}
}
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)