CommonSenseCode
CommonSenseCode

Reputation: 25418

Use 2 different ranges in Elasticsearch

I have this query that only works when I query for one field, but if I try to query range for two fields it throws an error:

{
  "query": {
    "range" : {
            "date" : {
                "gt" : "18/05/2017",
                "lt" : "19/05/2017"
            }
        },
    "range": {
            "number_of_cyclist_killed" : {
                "gt" : 0
            }

        }
  }
}

How can I query where number of cyclists > 0 and also in the date range?

Upvotes: 0

Views: 24

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52366

Try this:

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "date": {
              "gt": "18/05/2017",
              "lt": "19/05/2017"
            }
          }
        },
        {
          "range": {
            "number_of_cyclist_killed": {
              "gt": 0
            }
          }
        }
      ]
    }
  }
}

Upvotes: 3

Related Questions