gpt4 book ai didi

javascript - ElasticSearch - 按 : sorting and pagging 聚合/分组

转载 作者:太空宇宙 更新时间:2023-11-03 22:27:21 24 4
gpt4 key购买 nike

我正在尝试使用 Elasticsearch (2.4) 聚合来使用该查询对多个索引上的“productId”进行分组

{
"from": 0,
"size": 0,
"min_score": 0.15,
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"keywords.family": {
"query": "low fat milk",
"fuzziness": 0.7,
"boost": 5
}
}
}
]
}
}
}
},
"aggs": {
"group_by_0": {
"terms": {
"field": "productId",
"size": 50

},
"aggs": {
"top_tag_hits": {
"top_hits": {
"size": 1
}
}
}
}
}
}

1)我想按 _score 排序,所以我尝试使用

"order": {"_score": "desc"}

返回

"type": "aggregation_execution_exception",
"reason": "Invalid term-aggregator order path [_score]. Unknown aggregation [_score]"

2)另外,我正在尝试使用分页 - “size”键实际上起作用,但“from”键不起作用

**更新 - 聚合结果示例 **

{
"took": 5108,
"timed_out": false,
"_shards": {
"total": 105,
"successful": 105,
"failed": 0
},
"hits": {
"total": 9963,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by_0": {
"doc_count_error_upper_bound": 69,
"sum_other_doc_count": 9779,
"buckets": [
{
"key": 98761,
"doc_count": 36,
"top_tag_hits": {
"hits": {
"total": 36,
"max_score": 0.36901662,
"hits": [
{
"_index": "retailer-1",
"_type": "product",
"_id": "1409421",
"_score": 0.36901662,
"_source": {
"productId": 98761
}
}
]
}
}
},
{
"key": 107459,
"doc_count": 36,
"top_tag_hits": {
"hits": {
"total": 36,
"max_score": 0.42744976,
"hits": [
{
"_index": "retailer-2",
"_type": "product",
"_id": "1402563",
"_score": 0.42744976,
"_source": {
"productId": 107459
}
}
]
}
}
}
]
}
}
}

希望有人能帮忙

最佳答案

尝试以下查询

{
"from": 0,
"size": 0,
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"keywords.family": {
"query": "low fat milk",
"fuzziness": 0.7,
"boost": 5
}
}
}
]
}
}
}
},
"aggs": {
"group_by_0": {
"terms": {
"field": "productId",
"size": 50

},
"aggs": {
"top_tag_hits": {
"top_hits": {
"size": 1,
"sort": [
{
"_score": {
"order": "desc"
}
}
]
}
}
}
}
}
}

这将以分数降序排列热门命中。对于聚合桶上的分页,目前这是不可能的。可能会在新版本中获得此功能。

关于javascript - ElasticSearch - 按 : sorting and pagging 聚合/分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43831443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com