# How do I filter a regexp query by timestamp?

**URL:** https://discuss.elastic.co/t/how-do-i-filter-a-regexp-query-by-timestamp/139238
**Category:** Elasticsearch
**Created:** [July 9, 2018, 9:34pm UTC](https://discuss.elastic.co/t/how-do-i-filter-a-regexp-query-by-timestamp/139238 "2018-07-09T21:34:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ryan\_McGauley](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Ryan\_McGauley](https://discuss.elastic.co/u/Ryan_McGauley)
#### Post date: [July 9, 2018, 9:34pm UTC](https://discuss.elastic.co/t/how-do-i-filter-a-regexp-query-by-timestamp/139238/1 "2018-07-09T21:34:40Z")

</div>

I'm trying to make a query that will search based on a regular expression, then filter out the results based on a timestamp `eventTimeStamp`

[Here is the link to the query I was trying to execute](https://gist.github.com/rym23/95bfa590c4abee735156a63c220dbf2a)

[and the error that resulted from it](https://gist.github.com/rym23/ab821fb88e794917f885ddd31cc679ec)

I haven't been able to find anything about this elsewhere, which leads me to believe that what I'm trying to do is not possible.

Any help is appreciated.

---

<div class="post-metadata">

### Author: ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)
#### Post date: [July 10, 2018, 11:43am UTC](https://discuss.elastic.co/t/how-do-i-filter-a-regexp-query-by-timestamp/139238/2 "2018-07-10T11:43:39Z")

</div>

You have an error in the syntax.  
You cannot have regex and range queries on the same level.  
You need to combine them with a `bool query` for example :

```
GET firehose-raw/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "eventTimeStamp": {
            "lte": "2018-05-10T05:05:05.005"
          }
        }
      },
      "should": [
        {
          "regexp": {
            "rawlog.keyword": ".*unresponsive target=/.*"
          }
        }
      ]
    }
  }
}
```

---

<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: [August 7, 2018, 11:43am UTC](https://discuss.elastic.co/t/how-do-i-filter-a-regexp-query-by-timestamp/139238/3 "2018-08-07T11:43:44Z")

</div>

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