# Searching nested documents

**URL:** <https://discuss.elastic.co/t/searching-nested-documents/10232>\
**Category:** Elasticsearch\
**Created:** [January 5, 2013, 5:49am UTC](https://discuss.elastic.co/t/searching-nested-documents/10232 "2013-01-05T05:49:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aash\_dhariya](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@aash\_dhariya](https://discuss.elastic.co/u/aash_dhariya)\
**Post date:** [January 5, 2013, 5:49am UTC](https://discuss.elastic.co/t/searching-nested-documents/10232/1 "2013-01-05T05:49:10Z")

</div>

I have the user index with the following mappings:  
user:{  
properties:{  
tags: {  
type: "nested",  
properties: {  
type: {type: "string"}  
value: {type: "string"}  
}  
}  
}  
}

And I want to search for the ES document with the following values:

user : {  
tags: [  
{  
type: "joining\_year", value: "2001"  
},  
{  
type: "company", value: "Google"  
},  
{  
type: "college", value: "daiict"  
}  
]  
}

## What will be my ES query? I can used nested query to find a single tag having specific values. But when there are multiple nested tag documents, I don't know how to query them.

Thanks,  
Aash

--

---

<div class="post-metadata">

**Author:** ![aash\_dhariya](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@aash\_dhariya](https://discuss.elastic.co/u/aash_dhariya)\
**Post date:** [January 5, 2013, 11:38am UTC](https://discuss.elastic.co/t/searching-nested-documents/10232/2 "2013-01-05T11:38:35Z")

</div>

After some tries, here the query that fetches the results:  
filtered:{  
query: {match\_all: {}},  
filter: {and: [  
{nested: {path: "tags", query: {bool: {must: [{term: {"tags.type"  
=\> "joining\_year"}}, {term: {"tags.value" =\> "2001"}}]}}}}  
{nested: {path: "tags", query: {bool: {must: [{term: {"tags.type"  
=\> "company"}}, {term: {"tags.value" =\> "Google"}}]}}}}  
]}  
}  
On Sat, Jan 5, 2013 at 11:19 AM, aash dhariya [aash.discover@gmail.com](mailto:aash.discover@gmail.com)wrote:

> I have the user index with the following mappings:  
> user:{  
> properties:{  
> tags: {  
> type: "nested",  
> properties: {  
> type: {type: "string"}  
> value: {type: "string"}  
> }  
> }  
> }  
> }
> 
> And I want to search for the ES document with the following values:
> 
> user : {  
> tags: [  
> {  
> type: "joining\_year", value: "2001"  
> },  
> {  
> type: "company", value: "Google"  
> },  
> {  
> type: "college", value: "daiict"  
> }  
> ]  
> }
> 
> ## What will be my ES query? I can used nested query to find a single tag having specific values. But when there are multiple nested tag documents, I don't know how to query them.
> 
> Thanks,  
> Aash

--  
Thanks,  
Aash

--

---

<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 6, 2017, 2:57am UTC](https://discuss.elastic.co/t/searching-nested-documents/10232/3 "2017-07-06T02:57:48Z")

</div>


