我是Elastic Search的新手。我想从查询步骤的_source
中获取输出,以包含在aggs
步骤中。
示例数据:
{
"id": "1",
"description": "nyHlUN4vLVT6cOjcM1xf",
"locationData": [
{
"locationId": "001-00001",
"delivery": true
},
{
"locationId": "001-00002",
"delivery": false
}
]}
现在我得到基于id & locationId的输出。例如,对于id ='1' & locationId ='001 -00001',输出应为
{
"id": "1",
"description": "nyHlUN4vLVT6cOjcM1xf",
"locationData": [
{
"locationId": "001-00001",
"delivery": true
}
]}
它不能包含locationId等于001-00002的数据。
我尝试在这里使用聚合,但在这种方法中出现了另一个问题。我得到的locationData只有locationId等于001-00001,但是id
和description
没有包含在locationData
中。
下面是我使用的查询
{
"query": {
"bool": {
"must": [
{
"term": {
"id": {
"value": "1"
}
}
}
]
}
},
"aggs": {
"filtered_locations": {
"nested": {
"path": "locationData"
},
"aggs": {
"locations": {
"filter": {
"term": {
"locationData.locationId": "001-00001"
}
},
"aggs": {
"location_data": {
"top_hits": {
"_source": [
"id",
"description",
"locationData"
],
"size": 1
}
}
}
}
}
}
}
}
有人能在这方面提供帮助或为这种情况提供文档吗?
1条答案
按热度按时间9q78igpj1#
你真的需要聚合吗?您可以通过inner_hits恢复。
查询将是这样的:
查看inner_hits: