5

I cant figure out what's wrong with this query. Both "range" and "exists" work independently, but together I get parsing expection and range malformed query, expected END_OBJECT but found FIELD_NAME. Can someone figure out what's wrong with this query?

{
"query": {
  "range":{
     "@timestamp":{
        "gte":"2019-08-04T11:00:00",
        "lt":"2019-10-04T12:00:00"
     }
  },
  "exists": {
      "field": "params.zone"
  }  

},
"_source": ["@timestamp", "params.zone"]
}

1 Answer 1

10

If you want to combine several queries like you're doing with range and exists you need to use bool query and decided which of your clauses are mandatory (must), optional (should), filter (filter), or shouldn't be presented in results (must_not)

Query which would work could look like this (you're clauses are mandatory in this example):

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "gte": "2019-08-04T11:00:00",
              "lt": "2019-10-04T12:00:00"
            }
          }
        },
        {
          "exists": {
            "field": "params.zone"
          }
        }
      ]
    }
  },
  "_source": [
    "@timestamp",
    "params.zone"
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Mehrdad could you please upvote the answer as well, if it helped you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.