# Querying a nested field in elasticsearch

**URL:** <https://discuss.elastic.co/t/querying-a-nested-field-in-elasticsearch/61783>\
**Category:** Elasticsearch\
**Created:** [September 29, 2016, 7:59am UTC](https://discuss.elastic.co/t/querying-a-nested-field-in-elasticsearch/61783 "2016-09-29T07:59:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandhya\_Rathinapandi](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Sandhya\_Rathinapandi](https://discuss.elastic.co/u/Sandhya_Rathinapandi)\
**Post date:** [September 29, 2016, 7:59am UTC](https://discuss.elastic.co/t/querying-a-nested-field-in-elasticsearch/61783/1 "2016-09-29T07:59:38Z")

</div>

I have a nested field in the index and i am having issues with querying it.

Suppose i have the below json in my index:  
{car:[{name: abc, color:red},{name:xyz, color:blue}]}  
{car:[{name: abc1, color:red},{name:xyz1, color:black}]}

I am trying to search for all the red color cars:

{ "query": { "nested" : { "path" : "car", "score\_mode" : "avg","query" : { "bool" : { "must" : [{ "match" : {"car.color" : "red"} }]} } } }}'

I am getting all the four cars.

Kindly help us on querying this.

Thanks

---

<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 5, 2017, 10:16pm UTC](https://discuss.elastic.co/t/querying-a-nested-field-in-elasticsearch/61783/2 "2017-07-05T22:16:15Z")

</div>


