# ElasticSearch nested objects - get unique fields with thier respected values

**URL:** <https://discuss.elastic.co/t/elasticsearch-nested-objects-get-unique-fields-with-thier-respected-values/89691>\
**Category:** Elasticsearch\
**Created:** [June 16, 2017, 10:49am UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-get-unique-fields-with-thier-respected-values/89691 "2017-06-16T10:49:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aman\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@Aman\_Gupta](https://discuss.elastic.co/u/Aman_Gupta)\
**Post date:** [June 16, 2017, 10:49am UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-get-unique-fields-with-thier-respected-values/89691/1 "2017-06-16T10:49:39Z")

</div>

We are a bit confused on how to store the following data to retrieve it later with ease. We will have a million records, of following type :

{  
"width" : 720  
"height" : 200  
"coords" : [{  
"el" : "xyz",  
"x-y" : "100-50"  
},  
{  
"el" : "abc",  
"x-y" : "200-150"  
}]  
},  
{  
"width" : 1280  
"height" : 1000  
"coords" : [{  
"el" : "lmn",  
"x-y" : "400-50"  
},  
{  
"el" : "abc",  
"x-y" : "500-250"  
}]  
}

What type of aggregation query we will need to run to get the data in following form. As of now, i could only search for queries which return unique values with thier respective count (no. of occurances).

{  
"el" : "xyz",  
"x-y" : ["100-50"]  
},  
{  
"el" : "abc",  
"x-y" : ["200-150","500-250"]  
},  
{  
"el" : "lmn",  
"x-y" : ["400-50"]  
}

We have created a mapping, where "coords" is of type nested. We can still change the mapping to get the better performance and results as we are still in development phase.

---

<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:** [July 14, 2017, 10:49am UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-get-unique-fields-with-thier-respected-values/89691/2 "2017-07-14T10:49:58Z")

</div>

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