# Get unique documents based on 3 fields

**URL:** <https://discuss.elastic.co/t/get-unique-documents-based-on-3-fields/357785>\
**Category:** Elasticsearch\
**Created:** [April 19, 2024, 12:02pm UTC](https://discuss.elastic.co/t/get-unique-documents-based-on-3-fields/357785 "2024-04-19T12:02:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![akhil\_reddy](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@akhil\_reddy](https://discuss.elastic.co/u/akhil_reddy)\
**Post date:** [April 19, 2024, 12:02pm UTC](https://discuss.elastic.co/t/get-unique-documents-based-on-3-fields/357785/1 "2024-04-19T12:02:13Z")

</div>

Hi,  
I have an index with lot of data. Is there a way to get the unique documents from the index based on 3 fields. I tried collapse and aggregates  
collapse allows to get unique documents based on 1 field  
aggregate gives me the unique values from documents but it doesn't return the complete document based on unique fields.

ex:  
PUT myindex/\_doc/uid1  
{  
source: 'source1',  
client: 'client1',  
tag: 'tag1',  
combinations: ['rule1', 'rule2', 'rule3']  
}

PUT myindex/\_doc/uid2  
{  
source: 'source1',  
client: 'client1',  
tag: 'tag1',  
combinations: ['rule3', 'rule4', 'rule5']  
}

PUT myindex/\_doc/uid3  
{  
source: 'source2',  
client: 'client1',  
tag: 'tag1',  
combinations: ['rule7', 'rule2', 'rule3']  
}

With above data based on source, client and tag, I want to get docs uid1 and uid3 as uid 2 has same source, client and tag as uid1
