Filtering questions with more than four answers

Next, let's see how we can filter questions that have at least four answers. For this, there is a provision to filter parent documents based on the number of children they have. We can use the min_children attribute to implement this limit:

curl -XPOST 'localhost:9200/posts/post/_search' -d '{
  "query": {
    "has_child": {
      "type": "rating",
      "min_children": 4,
      "query": {
        "match_all": {}
      }
    }
  }
}'

Here, we are telling Elasticsearch to give all parent documents at least four children.

With this, we get the following result:

{ "took" : 3, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "posts", "_type" : "post", ...

Get Elasticsearch Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.