# Elasticsearch Head - Find and Remove Duplicate Documents

**URL:** https://discuss.elastic.co/t/elasticsearch-head-find-and-remove-duplicate-documents/257438
**Category:** Elasticsearch
**Created:** [December 3, 2020, 2:39am UTC](https://discuss.elastic.co/t/elasticsearch-head-find-and-remove-duplicate-documents/257438 "2020-12-03T02:39:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![test\_tester](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/test_tester/32/79990_2.png) [@test\_tester](https://discuss.elastic.co/u/test_tester)
#### Post date: [December 3, 2020, 2:39am UTC](https://discuss.elastic.co/t/elasticsearch-head-find-and-remove-duplicate-documents/257438/1 "2020-12-03T02:39:29Z")

</div>

Hi All,

Background:  
Inside my application, users noticed duplicate transactions -\> investigating deeper, we noticed that we have duplicates in our elasticsearch database, likely because we did not restart our logstash/filebeat servers properly.

Problem - duplicates of the same txn in elasticsearch:  
Example -\> txn\_ref "0011XX8711234".

Note that the values for the 'message body', fields are all the same with the exception of unique identifiers like id, createdDate and more.

So I read up on duplicates on other similar posts and came up with the following query to find:

POST -\> sample\_index\*/\_search

{"aggs":{"duplicate\_docs":{"terms":{"field":"source.txn\_ref","size":2,"min\_doc\_count":2}}}}

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/8/58531cc7d8d44a117cb1e1cd72b6738e0ef14b25.png)

The search results didn't matched with the duplicates identified by testers which probably meant the query fields aren't being used properly?

If anyone could advise on how I can go forward, please advise.

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: [December 31, 2020, 2:39am UTC](https://discuss.elastic.co/t/elasticsearch-head-find-and-remove-duplicate-documents/257438/2 "2020-12-31T02:39:59Z")

</div>

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