# Hits object not populated with nested query

**URL:** <https://discuss.elastic.co/t/hits-object-not-populated-with-nested-query/12225>\
**Category:** Elasticsearch\
**Created:** [June 2, 2013, 1:57pm UTC](https://discuss.elastic.co/t/hits-object-not-populated-with-nested-query/12225 "2013-06-02T13:57:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stewart\_Morgan](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Stewart\_Morgan](https://discuss.elastic.co/u/Stewart_Morgan)\
**Post date:** [June 2, 2013, 1:57pm UTC](https://discuss.elastic.co/t/hits-object-not-populated-with-nested-query/12225/1 "2013-06-02T13:57:00Z")

</div>

I have a problem with a nested query in elasticsearch. I'm building a  
complex nested query via the java api to run a filtered query over my  
index. The results get back from elasticsearch indicate that there is 1  
match ([total:1, took:79ms]), but this is not returning any "hits" as part  
of the response.

def response = client.search(request).actionGet()  
def searchHits = response.hits() // \<--- this is empty

result.total = searchHits.totalHits() // \<--- this is populated with one  
result.took = response.getTook()

Running the exact same query via curl or a rest client correctly brings  
back the entire matching document. As such I know the query is constructed  
correctly in both circumstances.

The size and from parameters are both set to the defaults, which should be  
returning documents.

If I move the nested query into the filter section the, I get the same  
matching document, but the hits() object is populated.

The query itself is below

{  
"filtered" : {  
"query" : {  
"bool" : {  
"must" : [ {  
"nested" : {  
"query" : {  
"bool" : {  
"must\_not" : {  
"bool" : {  
"must" : [ {  
"range" : {  
"nested.from" : {  
"from" : "2013-06-01T23:00:14.343Z",  
"to" : "2013-06-02T23:00:14.343Z",  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
}, {  
"term" : {  
"nested.status" : "accepted"  
}  
} ]  
}  
},  
"should" : [ {  
"bool" : {  
"must" : [ {  
"range" : {  
"nested.from" : {  
"from" : "2013-06-01T23:00:14.343Z",  
"to" : "2013-06-02T23:00:14.343Z",  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
}, {  
"term" : {  
"nested.status" : "saved"  
}  
} ]  
}  
} ]  
}  
},  
"path" : "nested"  
}  
} ]  
}  
} ]  
}  
},  
"filter" : {  
"and" : {  
"filters" : [ {  
"type" : {  
"value" : "user"  
}  
}]  
}  
}  
}  
}

I'm using it as a local node in a grails project with ES v 0.19.6

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:33am UTC](https://discuss.elastic.co/t/hits-object-not-populated-with-nested-query/12225/2 "2017-07-06T02:33:26Z")

</div>

Closed on July 6, 2017, 2:33am UTC


