title: Eliminate duplicates in elasticsearch query
body: <p>I have the problem that some documents are indexed twice or more so I want to filter out this duplicates when searching. I followed some other threads and built this query:</p>
  
  <pre><code>{
    "query" : { ... },
    "size" : 10,
    "from" : 0,
    "sort" : { ... },
    "aggs" : {
      "dedup" : {
        "terms" : {
          "field" : "content.keyword"
        },
        "aggs" : {
          "dedup_docs" : {
            "top_hits" : {
              "size" : 1
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>But it seems that this aggregation has no effect. I'm still getting duplicate results (documents with the same text in the content field).</p>
  
  <p>Request changed:</p>
  
  <pre><code>{
    "query" : { ... },
    "size" : 10,
    "from" : 0,
    "sort" : { ... },
    "collapse" : {
      "field" : "content.keyword"
    }
  }
  </code></pre>