我正在尝试在弹性搜索中进行存储桶聚合,该搜索仅在从查询返回的结果上运行。
似乎聚合在每次点击时运行,但只返回其中的一部分。这很好,但问题是从聚合返回的文档与从查询返回的文档不匹配。
这是映射:
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' },
};
Run Code Online (Sandbox Code Playgroud)
这是查询:
{
"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"
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 1
以下资源应有助于了解您观察到的行为和您的问题:
似乎聚合在每次点击时运行,但只返回其中的一部分。
是的,默认情况下,您拥有的术语聚合将仅返回前 10 个存储桶,您可以使用大小参数更新它(大小 0 将返回所有存储桶)。请参阅相关帖子显示所有 Elasticsearch 聚合存储桶。
问题是从聚合返回的文档与从查询返回的文档不匹配。
在 Elasticsearch 响应中,您应该看到前 10 个评分结果(同样,查询的根级别有一个大小参数,默认为 10 - 请参阅Elasticsearch From/Size Doc)以及聚合的前 10 个存储桶。得分最高的结果可能并不具有最常见的review.locationId。
我认为你的选择是:
| 归档时间: |
|
| 查看次数: |
3364 次 |
| 最近记录: |