# Remove duplicate recods and get the smallest record id

**URL:** <https://discuss.elastic.co/t/remove-duplicate-recods-and-get-the-smallest-record-id/149731>\
**Category:** Elasticsearch\
**Created:** [September 24, 2018, 8:25pm UTC](https://discuss.elastic.co/t/remove-duplicate-recods-and-get-the-smallest-record-id/149731 "2018-09-24T20:25:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkat\_venkat](https://avatars.discourse-cdn.com/v4/letter/v/f17d59/32.png) [@venkat\_venkat](https://discuss.elastic.co/u/venkat_venkat)\
**Post date:** [September 24, 2018, 8:25pm UTC](https://discuss.elastic.co/t/remove-duplicate-recods-and-get-the-smallest-record-id/149731/1 "2018-09-24T20:25:35Z")

</div>

Assuming I have data like:

rowid\_xfef,city,postal,address,name  
1,c1,p1,a1,n1  
2,c1,p1,a1,n1  
3,c2,p2,a2,n2  
4,c3,p3,a3,n3  
5,c3,p3,a3,n3  
6,c3,p3,a3,n3

I should match city,postal,address,and name and the record with lowest rowid should be printed.

Output should be:  
1,c1,p1,a1,n1  
3,c2,p2,a2,n2  
4,c3,p3,a3,n3

Please do the needful.

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [September 24, 2018, 9:29pm UTC](https://discuss.elastic.co/t/remove-duplicate-recods-and-get-the-smallest-record-id/149731/2 "2018-09-24T21:29:42Z")

</div>

Check out [this info](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_multi_field_terms_aggregation) on Multi-field terms aggregation.

If you happen to be using Logstash to ingest the data, consider using a [fingerprint field](https://www.elastic.co/guide/en/logstash/current/plugins-filters-fingerprint.html), which could then be aggregated much more quickly to determine where the duplicates are. Or you can use the fingerprint as the ID so you just have one copy of each unique `city,postal,address,name` tuple.

---

<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:** [October 22, 2018, 9:29pm UTC](https://discuss.elastic.co/t/remove-duplicate-recods-and-get-the-smallest-record-id/149731/3 "2018-10-22T21:29:44Z")

</div>

Closed on October 22, 2018, 9:29pm UTC

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