Elasticsearch聚合:如何对存储桶顺序进行排序 [英] Elasticsearch Aggregation: How to Sort Bucket Order
问题描述
ES版本:1.5(Amazon Elasticsearch)
ES Version: 1.5 (Amazon Elasticsearch)
我的目标:在特定字段上具有重复数据删除功能的搜索结果.我目前正在对聚合进行一些研究,以解决重复数据删除问题.因此,我的结果是一个带有1个大小的存储桶的列表存储桶.但是,我找不到订购存储桶列表的方法.
My goal: Have search results with deduplication on a certain field. I am currently doing some research with aggregation that deals with the deduplication. So, my result is a list buckets with 1-sized buckets. However, I can't find a way to order the list of buckets.
当前查询:
curl -XGET "http://localhost:9200/myidx/product/_search?search_type=count" -d '{
"size": 2,
"query": {
"function_score": {
"field_value_factor": {
"field": "relevance",
"factor": 2.0
},
"query": { "term": { "title": "abcd" } },
"score_mode": "multiply",
"boost_mode": "multiply"
}
},
"aggs": {
"unique": {
"terms": {
"field": "groupid",
"size": 2
},
"aggs": {
"sample": {
"top_hits": {
"size": 1
}
}
}
}
}
}'
结果:
{ ...
"aggregations": {
"unique": {
"doc_count_error_upper_bound": 1,
"sum_other_doc_count": 39,
"buckets": [
{
"key": 717878424,
"doc_count": 14,
"sample": {
"hits": {
"total": 14,
"max_score": 45.856163,
"hits": [
{
"_index": "myidx",
"_type": "product",
"_id": "89531",
"_score": 45.856163,
"_source": { ... }
}
]
}
}
},
{
"key": 717878423,
"doc_count": 8,
"sample": {
"hits": {
"total": 8,
"max_score": 68.78424,
"hits": [
{
"_index": "myidx",
"_type": "product",
"_id": "89517",
"_score": 68.78424,
"_source": { ... }
}
]
}
}
}
]
}
}
}
我想看到第二个存储桶,其中max_score = 68.78424为第一个.这可能吗?
I would like to see the second bucket with the max_score=68.78424 as the first. Is this possible?
如果不建议使用聚合,请告知.
If aggregations is not a recommended solution, please tell.
推荐答案
是的,您可以通过在文档的最高得分上添加另一个子聚合并对 unique
terms
根据该分数进行汇总.
Yes, you can do it by adding another sub-aggregation on the max document score and sorting the unique
terms
aggregation by that score.
curl -XGET "http://localhost:9200/myidx/product/_search?search_type=count" -d '{
"size": 2,
"query": {
"function_score": {
"field_value_factor": {
"field": "relevance",
"factor": 2.0
},
"query": { "term": { "title": "abcd" } },
"score_mode": "multiply",
"boost_mode": "multiply"
}
},
"aggs": {
"unique": {
"terms": {
"field": "groupid",
"size": 2,
"order": {
"max_score": "desc"
}
},
"aggs": {
"max_score": {
"max": {
"script": "doc.score"
}
},
"sample": {
"top_hits": {
"size": 1
}
}
}
}
}
}'
这篇关于Elasticsearch聚合:如何对存储桶顺序进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!