# Multi filter on nested object

**URL:** https://discuss.elastic.co/t/multi-filter-on-nested-object/10330
**Category:** Elasticsearch
**Created:** [January 14, 2013, 12:53pm UTC](https://discuss.elastic.co/t/multi-filter-on-nested-object/10330 "2013-01-14T12:53:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![David\_3](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@David\_3](https://discuss.elastic.co/u/David_3)
#### Post date: [January 14, 2013, 12:53pm UTC](https://discuss.elastic.co/t/multi-filter-on-nested-object/10330/1 "2013-01-14T12:53:18Z")

</div>

Is there a way to do a multi filter on a nested object to do something  
similar to left joining a table on itself in sql?

I have a nested object list which contains multiple object types. They all  
share the same id field as they are all of the same super Class type.  
ES creates a nested object using the super Class type.

I am trying to create a filter which will filter based on the object type  
and the id, I also need to filter more then one object type at the same  
time.  
I cannot use an OR filter because I need an exact match. When using an AND  
filter to join the nested filters it seems to just treat them as the same  
filter  
and returns nothing.

Here is an example of my query:

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"and": {  
"filters": [  
{  
"and": {  
"filters": [  
{  
"nested": {  
"filter": {  
"and": {  
"filters": [  
{  
"and": {  
"filters": [  
{  
"term": {  
"nested.data.type": "1"  
}  
},  
{  
"range": {  
"nested.data.id": {  
"from": 11,  
"to": 15,  
"include\_lower": true,  
"include\_upper": true  
}  
}  
}  
]  
}  
},  
{  
"and": {  
"filters": [  
{  
"term": {  
"nested.data.type": "3"  
}  
},  
{  
"term": {  
"nested.data.id": 25  
}  
}  
]  
}  
}  
]  
}  
},  
"path": "nested"  
}  
}  
]  
}  
}  
]  
}  
}  
}  
}  
}

--

---

<div class="post-metadata">

### Author: ![David\_3](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@David\_3](https://discuss.elastic.co/u/David_3)
#### Post date: [January 14, 2013, 2:49pm UTC](https://discuss.elastic.co/t/multi-filter-on-nested-object/10330/2 "2013-01-14T14:49:14Z")

</div>

I found a solution by using a nested filter for each object type in the  
list and ANDing them together. The overall filter which includes the nested  
filters returns the expected result. So it seems that the term and range  
filters cannot be included in a single nested filter to get the same result.

--

---

<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:56am UTC](https://discuss.elastic.co/t/multi-filter-on-nested-object/10330/3 "2017-07-06T02:56:38Z")

</div>


