# Return the Total Number of Duplicate Data/Docs

**URL:** <https://discuss.elastic.co/t/return-the-total-number-of-duplicate-data-docs/77714>\
**Category:** Elasticsearch\
**Created:** [March 7, 2017, 6:36pm UTC](https://discuss.elastic.co/t/return-the-total-number-of-duplicate-data-docs/77714 "2017-03-07T18:36:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmbtenorio](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@mmbtenorio](https://discuss.elastic.co/u/mmbtenorio)\
**Post date:** [March 7, 2017, 6:36pm UTC](https://discuss.elastic.co/t/return-the-total-number-of-duplicate-data-docs/77714/1 "2017-03-07T18:36:59Z")

</div>

Hello there!

I've been wondering if there's a way to get the total number of duplicate data in Elasticsearch?  
I'm using this query to get the duplicates, but somehow, even browsing the web, I can't find enough information about this. Somebody suggested to use a watch condition script, but I don't know how to start it off.

```
POST /sampleindex/_search 
{
   "size": 0,
   "aggs": {
      "duplicateCount": {
         "terms": {
            "field": "costInvoiceNumber",
            "min_doc_count": 2
         },
         "aggs": {
            "duplicateDocuments": {
               "top_hits": {}
            }
         }
      }
   },
   "query": {
      "range": {
         "costInvoiceDate": {
            "gte": "2017-01-31",
            "lte": "2017-02-03"
         }
      }
   }
}

```

Any response is highly appreciated. Thank you!

---

<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:** [April 4, 2017, 6:37pm UTC](https://discuss.elastic.co/t/return-the-total-number-of-duplicate-data-docs/77714/2 "2017-04-04T18:37:11Z")

</div>

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