1
我試圖在彈性搜索中執行存儲區聚合,該搜索只在查詢返回的結果上運行。如何僅聚合彈性搜索中查詢返回的結果
看來聚合運行在每個命中,但只返回它的一部分。這很好,但問題是從聚合返回的文檔與查詢返回的文檔不匹配。
這裏是映射:
LOCATION_MAPPING = {
id: { type: 'long' },
name: { type: 'text' },
street: { type: 'text' },
city: { type: 'text' },
state: { type: 'text' },
zip: { type: 'text' },
price: { type: 'text' },
geolocation: { type: 'geo_point' },
amenities: { type: 'nested' },
reviews: { type: 'nested' },
};
下面是該查詢:
{
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "1000yd",
"geolocation": [
-73.990768410025,
40.713144830193
]
}
},
"must": {
"multi_match": {
"query": "new york",
"fields": [
"name^2",
"city",
"state",
"zip"
],
"type": "best_fields"
}
}
}
},
"aggs": {
"reviews": {
"nested": {
"path": "reviews"
},
"aggs": {
"location": {
"terms": {
"field": "reviews.locationId"
},
"aggs": {
"avg_rating": {
"avg": {
"field": "reviews.rating"
}
}
}
}
}
}
}
}
您所提供的信息是不夠的,瞭解你的問題,請嘗試一下dding你的模式映射,你在獲得這個查詢和預期結果後得到的結果。 – user3775217
新增貼圖,希望它更清楚一點 – user3791980