# Problem for using regexp in DSL

**URL:** <https://discuss.elastic.co/t/problem-for-using-regexp-in-dsl/244809>\
**Category:** Elasticsearch\
**Created:** [August 13, 2020, 7:00am UTC](https://discuss.elastic.co/t/problem-for-using-regexp-in-dsl/244809 "2020-08-13T07:00:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrzhuang007](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Mrzhuang007](https://discuss.elastic.co/u/Mrzhuang007)\
**Post date:** [August 13, 2020, 7:00am UTC](https://discuss.elastic.co/t/problem-for-using-regexp-in-dsl/244809/1 "2020-08-13T07:00:50Z")

</div>

ES version: 6.8.6  
use something like this

```auto
GET _search
{
  "query": {
    "regexp": {
      "message": ".*error.*"
    }
  }
}

```

I can get some result, for example

```auto
 {
        "_index" : "filebeat-6.8.6-2020.08.13",
        "_type" : "doc",
        "_id" : "kiZ45nMBmMXSaaD4Zncy",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2020-08-13T06:18:35.468Z",
          "offset" : 19074,
          "message" : "[22:44:03] [ERROR] COMPILATION ERROR : ",
          "projectName" : "test-job-name",
          "buildNumber" : "1"
        }
      }

```

when I add the '[' charactor in regexp, it doen't return anything.

```auto
GET _search
{
  "query": {
    "regexp": {
      "message": ".*\\[error.*"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 13, 2020, 8:07am UTC](https://discuss.elastic.co/t/problem-for-using-regexp-in-dsl/244809/2 "2020-08-13T08:07:22Z")

</div>

One of the tricks here is, that you do not need to use a regular expression query at all. The reason is that a term like `error` or `compilation` will be stored in the index and thus made searchable. You can use a regular `match` query instead and still find your document.

In order to understand how a field is indexed and stored and searched I highly recommend you to read [Elasticsearch - The definitive guide](https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html), especially the [Search in Depth](https://www.elastic.co/guide/en/elasticsearch/guide/current/search-in-depth.html)

Despite its age this is still one of the best introductions into this topic.

---

<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:** [September 10, 2020, 8:07am UTC](https://discuss.elastic.co/t/problem-for-using-regexp-in-dsl/244809/3 "2020-09-10T08:07:22Z")

</div>

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