How to remove duplicate search result in elasticsearch?

前端 未结 1 1840
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 10:24

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
{
  \         


        
相关标签:
1条回答
  • 2020-12-15 11:26

    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:

    • search multi-index type
    • Remove duplicate documents from a search in Elasticsearch
    • Filter elasticsearch results to contain only unique documents based on one field value
    0 讨论(0)
提交回复
热议问题