With the indexed set of documents, let's say, we need to find out how many answers for a particular question got a rating of greater than 50. Let's try to find that out by issuing a query:
curl -XPOST localhost:9200/posts/post/_search -d '{ "query": { "filtered": { "query": { "text": {"question": " elasticsearch query to return all records "} }, "filter":{ "has_child": { "type": "rating", "query" : { "filtered": { "query": { "match_all": {}}, "filter" : { "and": [ {"term": {"accepted": yes}}, {"range": {"rating": {"gt" : 50}}} ] } } } } } } } }'