# Elimination of repeated document in elasticsearch aggregation query

**URL:** <https://discuss.elastic.co/t/elimination-of-repeated-document-in-elasticsearch-aggregation-query/127648>\
**Category:** Elasticsearch\
**Created:** [April 11, 2018, 2:08pm UTC](https://discuss.elastic.co/t/elimination-of-repeated-document-in-elasticsearch-aggregation-query/127648 "2018-04-11T14:08:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_Ahmed](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Ali\_Ahmed](https://discuss.elastic.co/u/Ali_Ahmed)\
**Post date:** [April 11, 2018, 2:08pm UTC](https://discuss.elastic.co/t/elimination-of-repeated-document-in-elasticsearch-aggregation-query/127648/1 "2018-04-11T14:08:33Z")

</div>

i have 5 documents of index which having a array of topics , 2 of them documents having a duplication of array something like below

```
   {
"_index": "testindex",
"_type": "testindex",
"_id": "125",
"_score": 1,
"_source": {
    "topics": [
        "Love",
        "Entertainment"
    ]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "126",
"_score": 1,
"_source": {
    "topics": [
        "Health",
        "Fitness"
    ]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "127",
"_score": 1,
"_source": {
    "topics": [
        "Health",
        "Fitness"
    ]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "128",
"_score": 1,
"_source": {
    "topics": [
        "Sports",
        "Cricket"
    ],
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "129",
"_score": 1,
"_source": {
    "topics": [
        "Fit",
        "gym"
    ],
}
}

```

here is my query of Elasticsearch

GET testindex/\_search

```
  {
      "size":0,
      "aggs": {
        "topics": {
          "terms": {
            "field": "topics.keyword",
            "size": 10
          },
          "aggs": {
            "testindex": {
              "top_hits": {
                "size": 10
              }
            }
          }
        }
      }
    }

```

_ **the result of my query is** _

```
    "aggregations": {
    "topics": {}
      "buckets": [
        {
            "key": "health",
            "doc_count": 2,
            "testindex": {
                "hits": {
                    "total": 2,
                    "max_score": 6.3823323,
                    "hits": [
                        {
                            "_index": "testindex",
                            "_type": "testindex",
                            "_id": "126",
                            "_score": 1,
                            "_source": {
                                "topics": [
                                    "Health",
                                ]
                            }
                        },
                        {
                            "_index": "testindex",
                            "_type": "testindex",
                            "_id": "127",
                            "_score": 1,
                            "_source": {
                                "topics": [
                                    "Health"
                                ]
                            }
                        },
                    ]
                }
            }
        },
        {
            "key": "Fitness",
            "doc_count": 2,
            "testindex": {
                "hits": {
                    "total": 2,
                    "max_score": 6.3823323,
                    "hits": [
                        {
                            "_index": "testindex",
                            "_type": "testindex",
                            "_id": "126",
                            "_score": 1,
                            "_source": {
                                "topics": [
                                    "Fitness",
                                ]
                            }
                        },
                        {
                            "_index": "testindex",
                            "_type": "testindex",
                            "_id": "127",
                            "_score": 1,
                            "_source": {
                                "topics": [
                                    "Fitness"
                                ]
                            }
                        },
                    ]
                }
            }
        },
    ]
}
}

```

Expectation is not duplication of bucket , i want single result of each index document ,  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 9, 2018, 2:08pm UTC](https://discuss.elastic.co/t/elimination-of-repeated-document-in-elasticsearch-aggregation-query/127648/2 "2018-05-09T14:08:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
