Book Image

Elasticsearch Blueprints

Book Image

Elasticsearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Searching questions based on a criteria of answers


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}}}
                ]
              }
            }
          }
        }
      }
    }
  }
}'