# Search nested "nested objects" using "wildcard paths"

**URL:** <https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138>\
**Category:** Elasticsearch\
**Created:** [December 20, 2012, 8:49pm UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138 "2012-12-20T20:49:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ash\_2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ash\_2](https://discuss.elastic.co/u/Ash_2)\
**Post date:** [December 20, 2012, 8:49pm UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138/1 "2012-12-20T20:49:58Z")

</div>

Hi,

I've been try to use Elasticsearch to query heavily nested documents like  
below (simplified document). In the document below, I would like to search  
for all color values without having to specify a full "path" in nested  
queries/filters. More like a wildcard path, for example color.\*.value=v2 .  
I could also include color types (blue, gray,red, etc) in the inner objects  
and remove one level of nesting, but I need the nesting to update  
(overwrite) a particular color type array (e.g. all blues). Including this  
information in the inner object and decreasing nesting levels will  
complicate updates.

If this is not possible, I would greatly appreciate it if I was pointed in  
the right direction.  
-Ash

{  
"color": {  
"blue": [  
{  
"name": "n3",  
"value": "v3",  
"type": "t3"  
},  
{  
"name": "n4",  
"value": "v4",  
"type": "t4"  
}  
],  
"gray": [  
{  
"name": "n5",  
"value": "v5",  
"type": "t5"  
},  
{  
"name": "n6",  
"value": "v6",  
"type": "t6"  
}  
],  
"red": [  
{  
"name": "n7",  
"value": "v7",  
"type": "t7"  
}  
]  
}  
}

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 20, 2012, 10:02pm UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138/2 "2012-12-20T22:02:16Z")

</div>

You can set "include\_in\_root" to true on your nested objects and use  
multi\_match query with a wildcard:  
{"multi\_match":{"query":"v2","fields":["color.\*.value"]}}. However, I would  
recommend moving color into the nested object and complicating updates. 🙂

On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:

> Hi,
> 
> I've been try to use Elasticsearch to query heavily nested documents like  
> below (simplified document). In the document below, I would like to search  
> for all color values without having to specify a full "path" in nested  
> queries/filters. More like a wildcard path, for example color.\*.value=v2 .  
> I could also include color types (blue, gray,red, etc) in the inner  
> objects and remove one level of nesting, but I need the nesting to update  
> (overwrite) a particular color type array (e.g. all blues). Including this  
> information in the inner object and decreasing nesting levels will  
> complicate updates.
> 
> If this is not possible, I would greatly appreciate it if I was pointed  
> in the right direction.  
> -Ash
> 
> {  
> "color": {  
> "blue": [  
> {  
> "name": "n3",  
> "value": "v3",  
> "type": "t3"  
> },  
> {  
> "name": "n4",  
> "value": "v4",  
> "type": "t4"  
> }  
> ],  
> "gray": [  
> {  
> "name": "n5",  
> "value": "v5",  
> "type": "t5"  
> },  
> {  
> "name": "n6",  
> "value": "v6",  
> "type": "t6"  
> }  
> ],  
> "red": [  
> {  
> "name": "n7",  
> "value": "v7",  
> "type": "t7"  
> }  
> ]  
> }  
> }

--

---

<div class="post-metadata">

**Author:** ![Ash\_2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ash\_2](https://discuss.elastic.co/u/Ash_2)\
**Post date:** [December 21, 2012, 12:22am UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138/3 "2012-12-21T00:22:40Z")

</div>

Thank you for your reply.

Multi\_match will only work if I was matching a single field. From what I  
understand this would completely omit the structure of the data and I won't  
be able to issue nested queries. As an example, the following query should  
not return any hits, but it's not.

{  
"query": {  
"nested": {  
"path": "color",  
"query": {  
"bool": {  
"must": [  
{"multi\_match":{"query":"v3","fields":[  
"color._.value"]}},  
{"multi\_match":{"query":"n4","fields":[  
"color._.name"]}}  
]  
}  
}  
}  
}  
}

On Thursday, 20 December 2012 14:02:16 UTC-8, Igor Motov wrote:

> You can set "include\_in\_root" to true on your nested objects and use  
> multi\_match query with a wildcard:  
> {"multi\_match":{"query":"v2","fields":["color.\*.value"]}}. However, I  
> would recommend moving color into the nested object and complicating  
> updates. 🙂
> 
> On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:
> 
> > Hi,
> > 
> > I've been try to use Elasticsearch to query heavily nested documents like  
> > below (simplified document). In the document below, I would like to search  
> > for all color values without having to specify a full "path" in nested  
> > queries/filters. More like a wildcard path, for example color.\*.value=v2  
> > .  
> > I could also include color types (blue, gray,red, etc) in the inner  
> > objects and remove one level of nesting, but I need the nesting to update  
> > (overwrite) a particular color type array (e.g. all blues). Including this  
> > information in the inner object and decreasing nesting levels will  
> > complicate updates.
> > 
> > If this is not possible, I would greatly appreciate it if I was pointed  
> > in the right direction.  
> > -Ash
> > 
> > {  
> > "color": {  
> > "blue": [  
> > {  
> > "name": "n3",  
> > "value": "v3",  
> > "type": "t3"  
> > },  
> > {  
> > "name": "n4",  
> > "value": "v4",  
> > "type": "t4"  
> > }  
> > ],  
> > "gray": [  
> > {  
> > "name": "n5",  
> > "value": "v5",  
> > "type": "t5"  
> > },  
> > {  
> > "name": "n6",  
> > "value": "v6",  
> > "type": "t6"  
> > }  
> > ],  
> > "red": [  
> > {  
> > "name": "n7",  
> > "value": "v7",  
> > "type": "t7"  
> > }  
> > ]  
> > }  
> > }

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 21, 2012, 12:29am UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138/4 "2012-12-21T00:29:16Z")

</div>

Exactly! That's why I recommended moving color into the nested object.

On Thursday, December 20, 2012 7:22:40 PM UTC-5, Ash wrote:

> Thank you for your reply.
> 
> Multi\_match will only work if I was matching a single field. From what I  
> understand this would completely omit the structure of the data and I won't  
> be able to issue nested queries. As an example, the following query should  
> not return any hits, but it's not.
> 
> {  
> "query": {  
> "nested": {  
> "path": "color",  
> "query": {  
> "bool": {  
> "must": [  
> {"multi\_match":{"query":"v3","fields":[  
> "color._.value"]}},  
> {"multi\_match":{"query":"n4","fields":[  
> "color._.name"]}}  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> On Thursday, 20 December 2012 14:02:16 UTC-8, Igor Motov wrote:
> 
> > You can set "include\_in\_root" to true on your nested objects and use  
> > multi\_match query with a wildcard:  
> > {"multi\_match":{"query":"v2","fields":["color.\*.value"]}}. However, I  
> > would recommend moving color into the nested object and complicating  
> > updates. 🙂
> > 
> > On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:
> > 
> > > Hi,
> > > 
> > > I've been try to use Elasticsearch to query heavily nested documents  
> > > like below (simplified document). In the document below, I would like to  
> > > search for all color values without having to specify a full "path" in  
> > > nested queries/filters. More like a wildcard path, for example  
> > > color.\*.value=v2 .  
> > > I could also include color types (blue, gray,red, etc) in the inner  
> > > objects and remove one level of nesting, but I need the nesting to update  
> > > (overwrite) a particular color type array (e.g. all blues). Including this  
> > > information in the inner object and decreasing nesting levels will  
> > > complicate updates.
> > > 
> > > If this is not possible, I would greatly appreciate it if I was pointed  
> > > in the right direction.  
> > > -Ash
> > > 
> > > {  
> > > "color": {  
> > > "blue": [  
> > > {  
> > > "name": "n3",  
> > > "value": "v3",  
> > > "type": "t3"  
> > > },  
> > > {  
> > > "name": "n4",  
> > > "value": "v4",  
> > > "type": "t4"  
> > > }  
> > > ],  
> > > "gray": [  
> > > {  
> > > "name": "n5",  
> > > "value": "v5",  
> > > "type": "t5"  
> > > },  
> > > {  
> > > "name": "n6",  
> > > "value": "v6",  
> > > "type": "t6"  
> > > }  
> > > ],  
> > > "red": [  
> > > {  
> > > "name": "n7",  
> > > "value": "v7",  
> > > "type": "t7"  
> > > }  
> > > ]  
> > > }  
> > > }

--

---

<div class="post-metadata">

**Author:** ![Ash\_2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ash\_2](https://discuss.elastic.co/u/Ash_2)\
**Post date:** [December 21, 2012, 12:53am UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138/5 "2012-12-21T00:53:36Z")

</div>

Thank you for clarifying this.

On Thursday, 20 December 2012 16:29:16 UTC-8, Igor Motov wrote:

> Exactly! That's why I recommended moving color into the nested object.
> 
> On Thursday, December 20, 2012 7:22:40 PM UTC-5, Ash wrote:
> 
> > Thank you for your reply.
> > 
> > Multi\_match will only work if I was matching a single field. From what I  
> > understand this would completely omit the structure of the data and I won't  
> > be able to issue nested queries. As an example, the following query should  
> > not return any hits, but it's not.
> > 
> > {  
> > "query": {  
> > "nested": {  
> > "path": "color",  
> > "query": {  
> > "bool": {  
> > "must": [  
> > {"multi\_match":{"query":"v3","fields":[  
> > "color._.value"]}},  
> > {"multi\_match":{"query":"n4","fields":[  
> > "color._.name"]}}  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > On Thursday, 20 December 2012 14:02:16 UTC-8, Igor Motov wrote:
> > 
> > > You can set "include\_in\_root" to true on your nested objects and use  
> > > multi\_match query with a wildcard:  
> > > {"multi\_match":{"query":"v2","fields":["color.\*.value"]}}. However, I  
> > > would recommend moving color into the nested object and complicating  
> > > updates. 🙂
> > > 
> > > On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I've been try to use Elasticsearch to query heavily nested documents  
> > > > like below (simplified document). In the document below, I would like to  
> > > > search for all color values without having to specify a full "path" in  
> > > > nested queries/filters. More like a wildcard path, for example  
> > > > color.\*.value=v2 .  
> > > > I could also include color types (blue, gray,red, etc) in the inner  
> > > > objects and remove one level of nesting, but I need the nesting to update  
> > > > (overwrite) a particular color type array (e.g. all blues). Including this  
> > > > information in the inner object and decreasing nesting levels will  
> > > > complicate updates.
> > > > 
> > > > If this is not possible, I would greatly appreciate it if I was  
> > > > pointed in the right direction.  
> > > > -Ash
> > > > 
> > > > {  
> > > > "color": {  
> > > > "blue": [  
> > > > {  
> > > > "name": "n3",  
> > > > "value": "v3",  
> > > > "type": "t3"  
> > > > },  
> > > > {  
> > > > "name": "n4",  
> > > > "value": "v4",  
> > > > "type": "t4"  
> > > > }  
> > > > ],  
> > > > "gray": [  
> > > > {  
> > > > "name": "n5",  
> > > > "value": "v5",  
> > > > "type": "t5"  
> > > > },  
> > > > {  
> > > > "name": "n6",  
> > > > "value": "v6",  
> > > > "type": "t6"  
> > > > }  
> > > > ],  
> > > > "red": [  
> > > > {  
> > > > "name": "n7",  
> > > > "value": "v7",  
> > > > "type": "t7"  
> > > > }  
> > > > ]  
> > > > }  
> > > > }

--

---

<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:58am UTC](https://discuss.elastic.co/t/search-nested-nested-objects-using-wildcard-paths/10138/6 "2017-07-06T02:58:54Z")

</div>


