# Combining bool and range queries

**URL:** <https://discuss.elastic.co/t/combining-bool-and-range-queries/82729>\
**Category:** Elasticsearch\
**Created:** [April 18, 2017, 2:03pm UTC](https://discuss.elastic.co/t/combining-bool-and-range-queries/82729 "2017-04-18T14:03:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [April 18, 2017, 2:03pm UTC](https://discuss.elastic.co/t/combining-bool-and-range-queries/82729/1 "2017-04-18T14:03:32Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [April 18, 2017, 8:01pm UTC](https://discuss.elastic.co/t/combining-bool-and-range-queries/82729/2 "2017-04-18T20:01:01Z")

</div>

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"
            }
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 16, 2017, 8:12pm UTC](https://discuss.elastic.co/t/combining-bool-and-range-queries/82729/3 "2017-05-16T20:12:51Z")

</div>

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