# Problem with combined nested bool filters (nested key/value matching)

**URL:** <https://discuss.elastic.co/t/problem-with-combined-nested-bool-filters-nested-key-value-matching/19381>\
**Category:** Elasticsearch\
**Created:** [August 21, 2014, 4:44am UTC](https://discuss.elastic.co/t/problem-with-combined-nested-bool-filters-nested-key-value-matching/19381 "2014-08-21T04:44:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drew\_Kutcharian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drew_kutcharian/32/742_2.png) [@Drew\_Kutcharian](https://discuss.elastic.co/u/Drew_Kutcharian)\
**Post date:** [August 21, 2014, 4:44am UTC](https://discuss.elastic.co/t/problem-with-combined-nested-bool-filters-nested-key-value-matching/19381/1 "2014-08-21T04:44:29Z")

</div>

Hey Guys,

Seems like there is an issue with a combined bool filter with nested docs.

I have the following mapping:

{  
"mappings": {  
"test": {  
"properties": {  
"name": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"attributes": {  
"type": "nested",  
"properties": {  
"name": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"stringValue": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"doubleValue": {  
"type": "double"  
}  
}  
}  
}  
}  
}  
}  
And I index the following document in it:

{  
"name": "John Stamos",  
"attributes": [  
{  
"name": "Name",  
"stringValue": "John"  
},  
{  
"name": "Age",  
"doubleValue": 34  
}  
]  
}  
If I run the following query, I get the correct result, which is the indexed document:

{  
"query": {  
"filtered": {  
"filter": {  
"nested": {  
"path": "attributes",  
"filter": {  
"bool": {  
"must": [  
{  
"bool": {  
"must": [  
{  
"term": {  
"attributes.name": "Name"  
}  
},  
{  
"term": {  
"attributes.stringValue": "John"  
}  
}  
]  
}  
}  
]  
}  
}  
}  
}  
}  
}  
}  
The query also works correctly if I filter by "Age". But if I combine two bool filters ("Name" and "Age"), then I don't get any results.

{  
"query": {  
"filtered": {  
"filter": {  
"nested": {  
"path": "attributes",  
"filter": {  
"bool": {  
"must": [  
{  
"bool": {  
"must": [  
{  
"term": {  
"attributes.name": "Name"  
}  
},  
{  
"term": {  
"attributes.stringValue": "John"  
}  
}  
]  
}  
},  
{  
"bool": {  
"must": [  
{  
"term": {  
"attributes.name": "Age"  
}  
},  
{  
"range": {  
"attributes.doubleValue": {  
"gt": 5  
}  
}  
}  
]  
}  
}  
]  
}  
}  
}  
}  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5E52EB8D-3FB3-41F3-9583-7493255AEE66%40venarc.com](https://groups.google.com/d/msgid/elasticsearch/5E52EB8D-3FB3-41F3-9583-7493255AEE66%40venarc.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Drew\_Kutcharian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drew_kutcharian/32/742_2.png) [@Drew\_Kutcharian](https://discuss.elastic.co/u/Drew_Kutcharian)\
**Post date:** [August 21, 2014, 10:41pm UTC](https://discuss.elastic.co/t/problem-with-combined-nested-bool-filters-nested-key-value-matching/19381/2 "2014-08-21T22:41:01Z")

</div>

I was able to get this to work. The problem was that I had to put the "bool" filter before the "nested" filter so now what I have is "bool" -\> "nested" -\> "bool".

On Aug 20, 2014, at 9:44 PM, Drew Kutcharian [drew@venarc.com](mailto:drew@venarc.com) wrote:

> Hey Guys,
> 
> Seems like there is an issue with a combined bool filter with nested docs.
> 
> I have the following mapping:
> 
> {  
> "mappings": {  
> "test": {  
> "properties": {  
> "name": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "attributes": {  
> "type": "nested",  
> "properties": {  
> "name": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "stringValue": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "doubleValue": {  
> "type": "double"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> And I index the following document in it:
> 
> {  
> "name": "John Stamos",  
> "attributes": [  
> {  
> "name": "Name",  
> "stringValue": "John"  
> },  
> {  
> "name": "Age",  
> "doubleValue": 34  
> }  
> ]  
> }  
> If I run the following query, I get the correct result, which is the indexed document:
> 
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "nested": {  
> "path": "attributes",  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "attributes.name": "Name"  
> }  
> },  
> {  
> "term": {  
> "attributes.stringValue": "John"  
> }  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> The query also works correctly if I filter by "Age". But if I combine two bool filters ("Name" and "Age"), then I don't get any results.
> 
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "nested": {  
> "path": "attributes",  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "attributes.name": "Name"  
> }  
> },  
> {  
> "term": {  
> "attributes.stringValue": "John"  
> }  
> }  
> ]  
> }  
> },  
> {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "attributes.name": "Age"  
> }  
> },  
> {  
> "range": {  
> "attributes.doubleValue": {  
> "gt": 5  
> }  
> }  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5E52EB8D-3FB3-41F3-9583-7493255AEE66%40venarc.com](https://groups.google.com/d/msgid/elasticsearch/5E52EB8D-3FB3-41F3-9583-7493255AEE66%40venarc.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/11D468C1-BC42-46BE-A163-1E328AF000CD%40venarc.com](https://groups.google.com/d/msgid/elasticsearch/11D468C1-BC42-46BE-A163-1E328AF000CD%40venarc.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:07am UTC](https://discuss.elastic.co/t/problem-with-combined-nested-bool-filters-nested-key-value-matching/19381/3 "2017-07-06T01:07:05Z")

</div>


