问题描述
我的所有文档都有一个 uid
字段,其中的ID将文档链接到用户。有多个文档具有相同的 uid
。
我想对所有只返回/ code>。
选择相关文档的查询是一个简单的
你需要一个聚合。 p>
根据您的具体情况:
{
查询:{
multi_match:{
...
}
},
aggs:{
top-uids
条款:{
field:uid
},
aggs:{
top_uids_hits:{
top_hits :{
sort:[
{
_score:{
order:de sc
}
}
],
size:1
}
}
}
}
}
}
上面的查询执行你的 multi_match
根据 uid
查询并聚合结果。对于每个uid bucket,它只返回一个结果,但是桶中的所有文档都是根据 _score
按照后代顺序排序的。
All my documents have a uid
field with an ID that links the document to a user. There are multiple documents with the same uid
.
I want to perform a search over all the documents returning only the highest scoring document per unique uid
.
The query selecting the relevant documents is a simple multi_match
query.
You need a top_hits
aggregation.
And for your specific case:
{
"query": {
"multi_match": {
...
}
},
"aggs": {
"top-uids": {
"terms": {
"field": "uid"
},
"aggs": {
"top_uids_hits": {
"top_hits": {
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"size": 1
}
}
}
}
}
}
The query above does perform your multi_match
query and aggregates the results based on uid
. For each uid bucket it returns only one result, but after all the documents in the bucket were sorted based on _score
in descendant order.
这篇关于过滤弹性搜索结果仅包含基于一个字段值的唯一文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!