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"
}
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"
}
Elasticsearch is a powerful search engine that can be used to search for documents and other data stored in an index. One way to avoid duplicates in Elasticsearch is to use the "dedup" processor, which will remove duplicate documents from the search results.
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
}
}
}
}
}
}
This might help you:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With