# Combine a query with term and range

**URL:** <https://discuss.elastic.co/t/combine-a-query-with-term-and-range/165771>\
**Category:** Elasticsearch\
**Created:** [January 25, 2019, 12:18pm UTC](https://discuss.elastic.co/t/combine-a-query-with-term-and-range/165771 "2019-01-25T12:18:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmmartinez](https://avatars.discourse-cdn.com/v4/letter/l/34f0e0/32.png) [@lmmartinez](https://discuss.elastic.co/u/lmmartinez)\
**Post date:** [January 25, 2019, 12:18pm UTC](https://discuss.elastic.co/t/combine-a-query-with-term-and-range/165771/1 "2019-01-25T12:18:19Z")

</div>

I have an index with a lot of docs. I have intended to send a query via api, to obtain a count of documents that contain an exact phrase in a portion of the message in this index.

The document has a field call event, and I look for the text Server unresponsive in this field. For example, the document in the field event has the value:

...Action Removed" Reason="Server unresponsive...

And I query if the field event contains Server unresponsive from now to -15m

I have constructed this query:

```
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {"@timestamp" : {"gt" : "now-15m"}}
        },
        {
          "term": { "event": "Server unresponsive"}
        }
      ]
    }
  }
}

```

I want the result for the last 15 minutes, but when I launch the query show me 0 results, but in Kibana, the equivalent search query, show me X hits at the same time.

Why this query does not match correctly this result?. I have used match options and the result is the same, 0 hits. If the query has with "query\_string" the result shows me, all the hits in all my docs in the index, but I don't know how to limit the result to the last 15 minutes.

---

<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:** [February 22, 2019, 12:18pm UTC](https://discuss.elastic.co/t/combine-a-query-with-term-and-range/165771/2 "2019-02-22T12:18:20Z")

</div>

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