如何在elasticsearch中删除重复的搜索结果? [英] How to remove duplicate search result in elasticsearch?
本文介绍了如何在elasticsearch中删除重复的搜索结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先创建一些示例数据(e1,e2,e3 是类型,test 是索引名称):
First Create some example data (e1,e2,e3 are types and test is the index name):
PUT test/e1/1
{
"id":1
"subject": "subject 1"
}
PUT test/e2/1
{
"id":1
"subject": "subject 2"
}
PUT test/e3/2
{
"id":2
"subject": "subject 3"
}
现在我的问题是:我怎样才能得到这两个数据?删除 curl -XGET _search
结果中具有相同 id 的重复数据.
Now my question is: how can I get just these two data? remove duplicate data with the same id in the curl -XGET _search
result.
test/e1/1
{
"id":1
"subject": "subject 1"
}
test/e3/2
{
"id":2
"subject": "subject 3"
}
推荐答案
首先,您需要跨多个索引进行搜索.
然后,在结果上删除重复的 ID.
First you will need to search across multiple index.
Then, on the result remove the duplicate ID.
POST http://myElastic.com/test/e1,e2,e3/_search
{
"aggs":{
"dedup" : {
"terms":{
"field": "id"
},
"aggs":{
"dedup_docs":{
"top_hits":{
"size":1
}
}
}
}
}
}
这可能对您有所帮助:
这篇关于如何在elasticsearch中删除重复的搜索结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文