# Nested query bug?

**URL:** https://discuss.elastic.co/t/nested-query-bug/8518
**Category:** Elasticsearch
**Created:** [July 25, 2012, 9:40pm UTC](https://discuss.elastic.co/t/nested-query-bug/8518 "2012-07-25T21:40:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Zmicier](https://avatars.discourse-cdn.com/v4/letter/z/ecc23a/32.png) [@Zmicier](https://discuss.elastic.co/u/Zmicier)
#### Post date: [July 25, 2012, 9:40pm UTC](https://discuss.elastic.co/t/nested-query-bug/8518/1 "2012-07-25T21:40:45Z")

</div>

Queries are automatically constructed in my system, and sometimes they  
involve multiple levels of testing. Today I saw an example of two queries,  
that seem equivalent to me, but they produce different results on run on  
elastic. Perhaps Shay or others can clarify as to what is going on here.

Query #1 (straightforward "and' of two fields), 1723 results.

{  
"query" : {  
"bool" : {  
"must" : [ {  
"nested" : {  
"query" : {  
"range" : {  
"content.publish\_date" : {  
"from" : null,  
"to" : "2012-03-14T03:59:59.999Z",  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
},  
"path" : "content"  
}  
}, {  
"nested" : {  
"query" : {  
"text" : {  
"content.text" : {  
"query" : "stop",  
"type" : "boolean",  
"operator" : "AND"  
}  
}  
},  
"path" : "content"  
}  
} ]  
}  
}  
}

Query #2 (additional artificial nesting level is added wrapping the first  
query, this is a dummy toy example just to show the behavior), although the  
query seems to me totally equivalent to the first one, it produces 3376  
results, with some results not satisfying both of "and" conditions.

{  
"query" : {  
"nested" : {  
"query" : {  
"bool" : {  
"must" : [ {  
"nested" : {  
"query" : {  
"range" : {  
"content.publish\_date" : {  
"from" : null,  
"to" : "2012-03-14T03:59:59.999Z",  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
},  
"path" : "content"  
}  
}, {  
"nested" : {  
"query" : {  
"text" : {  
"content.text" : {  
"query" : "stop",  
"type" : "boolean",  
"operator" : "AND"  
}  
}  
},  
"path" : "content"  
}  
} ]  
}  
},  
"path" : "content"  
}  
}  
}

Anybody understands what is going on here?

---

<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, 3:18am UTC](https://discuss.elastic.co/t/nested-query-bug/8518/2 "2017-07-06T03:18:59Z")

</div>


