Combining bool and range queries

After seeing a few answers, I still didnt get a full grip on this issue.

I want to mix the bool and range query.
For an example I want to dinf all logs that terminationCauseis success in the last 5 minutes.

Something like this:
{
"query":{
"query": {
"bool":{
"must" : [
{"term" : {"terminationCause": "SUCCESS"}}
]
}
}
},
{
"query": {
"range" : {
"msgSubmissionTime" : {
"gte" : "now-2m",
"lt" : "now"
}
}
}
}
}

How can I do this?

(Sorry about the identation from some reason it didnt work)

2 Likes

I believe you are looking for something like this. Add both conditions to the must array in the query:

{
  "query": {
    "bool": {
      "must": [{
          "term": {
            "terminationCause": "SUCCESS"
          }
        },
        {
          "range": {
            "msgSubmissionTime": {
              "gte": "now-2m",
              "lt": "now"
            }
          }
        }
      ]
    }
  }
}
6 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.