# How to find the distinct values in a nested type field in elasticsearch? Can anyone provide one example?

**URL:** <https://discuss.elastic.co/t/how-to-find-the-distinct-values-in-a-nested-type-field-in-elasticsearch-can-anyone-provide-one-example/156384>\
**Category:** Elasticsearch\
**Created:** [November 13, 2018, 4:27am UTC](https://discuss.elastic.co/t/how-to-find-the-distinct-values-in-a-nested-type-field-in-elasticsearch-can-anyone-provide-one-example/156384 "2018-11-13T04:27:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepak643](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak643/32/45940_2.png) [@deepak643](https://discuss.elastic.co/u/deepak643)\
**Post date:** [November 13, 2018, 4:27am UTC](https://discuss.elastic.co/t/how-to-find-the-distinct-values-in-a-nested-type-field-in-elasticsearch-can-anyone-provide-one-example/156384/1 "2018-11-13T04:27:26Z")

</div>

I am looking for one example on how to extract distinct values of a nested type property in elastic search. Could anyone provide an example?

I have a below query where I am trying to retrieve distinct values of "batchId" from nested type "admin" as follows:

```
{
	"aggs" : {
		"groupBatches" : {
			"nested": {
                "path": "admin"
			},
			"aggs" : {
				"batches" : {
					"terms" : {"field" : "admin.ids.batchId"} 
				}
			}
		}
	}
}

```

If what I am trying is wrong, Please provide some example for better understanding.

---

<div class="post-metadata">

**Author:** ![deepak643](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak643/32/45940_2.png) [@deepak643](https://discuss.elastic.co/u/deepak643)\
**Post date:** [November 13, 2018, 4:36am UTC](https://discuss.elastic.co/t/how-to-find-the-distinct-values-in-a-nested-type-field-in-elasticsearch-can-anyone-provide-one-example/156384/2 "2018-11-13T04:36:54Z")

</div>

@dadoonet  
Hi David,  
Could you please take a look?

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 11, 2018, 4:37am UTC](https://discuss.elastic.co/t/how-to-find-the-distinct-values-in-a-nested-type-field-in-elasticsearch-can-anyone-provide-one-example/156384/3 "2018-12-11T04:37:00Z")

</div>

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