【发布时间】:2016-01-29 00:33:24
【问题描述】:
我正在尝试找到查询返回排序集的最佳解决方案,然后我使用 aggs 删除重复项,这很好,但是当我在查询结果上添加排序时,例如
"query": {..},
"sort": {.. "body.make": "asc" ..}
我希望 aggs 也按该顺序返回结果,但它似乎总是按查询分数排序。
// Here I'm collecting all body.vin values to remove duplicates
// and then returning only the first in each result set.
"aggs": {
"dedup": {
"terms": {
"size": 8,
"field": "body.vin"
},
"aggs": {
"dedup_docs": {
"top_hits": {
"size": 1,
"_source": false
}
}
}
}
},
我尝试在两者之间放置一个术语聚合,看看是否会排序:
// here again same thing, however I attempt to sort on body.make
// in the document, however I now realize that my bucket result
// being each a collection of the duplicates, will sort each duplicate
// and not on the last results.
"aggs": {
"dedup": {
"terms": {
"size": 8,
"field": "body.vin"
},
"aggs": {
"order": {
"terms": {
"field": "body.make",
"order": {
"_term": "asc"
}
},
"aggs": {
"dedup_docs": {
"top_hits": {
"size": 1,
"_source": false
}
}
}
}
}
}
},
但是聚合的结果总是基于分数。
我还玩弄了基于查询排序调整分数的想法或解决方案,这样聚合将根据分数返回正确的顺序,但似乎没有做任何事情这是sort: {}。
如果有人成功地对结果进行排序、删除重复项或想法/建议,请告诉我。
【问题讨论】:
标签: elasticsearch