# Kibana Search - Regex

**URL:** https://discuss.elastic.co/t/kibana-search-regex/139090
**Category:** Kibana
**Created:** [July 9, 2018, 6:32am UTC](https://discuss.elastic.co/t/kibana-search-regex/139090 "2018-07-09T06:32:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![VietCong](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@VietCong](https://discuss.elastic.co/u/VietCong)
#### Post date: [July 9, 2018, 6:32am UTC](https://discuss.elastic.co/t/kibana-search-regex/139090/1 "2018-07-09T06:32:53Z")

</div>

Hi,

I have this Kibana Search using regex and don't understand why it is not working. The search string is legal according to Query DSL filter but it gives me error "Courier Fetch: 124 of 1830 shards failed." Is there the special characters that I need to escape?

please see my filter syntax below:

```
{
  "query": {
    "regexp": {
      "message": "(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$]).{8,20}"
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)
#### Post date: [July 9, 2018, 1:28pm UTC](https://discuss.elastic.co/t/kibana-search-regex/139090/2 "2018-07-09T13:28:15Z")

</div>

I believe that you're hitting the `too_complex_to_determinize_exception` error that Elasticsearch is throwing when you try to use a RegEx that is too complex and would result in too high of memory usage.

If you try to execute a query similar to the following via DevTools:

```auto
GET logstash-*/_search
{
  "query": {
    "regexp": {
      "message": "(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$]).{8,20}"
    }
  }
}

```

You'll see the following error response:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n \"regexp\" : {\n \"message\" : {\n \"value\" : \"(?=.*\\\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$]).{8,20}\",\n \"flags_value\" : 65535,\n \"max_determinized_states\" : 10000,\n \"boost\" : 1.0\n }\n }\n}",
        "index_uuid": "2vspEvQ2Q6m0RmUwN_6_fQ",
        "index": "logstash-0"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "logstash-0",
        "node": "h9_nyEpyTS2H2Xa7_ZF_3w",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n \"regexp\" : {\n \"message\" : {\n \"value\" : \"(?=.*\\\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$]).{8,20}\",\n \"flags_value\" : 65535,\n \"max_determinized_states\" : 10000,\n \"boost\" : 1.0\n }\n }\n}",
          "index_uuid": "2vspEvQ2Q6m0RmUwN_6_fQ",
          "index": "logstash-0",
          "caused_by": {
            "type": "too_complex_to_determinize_exception",
            "reason": "Determinizing (?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#$]).{8,20} would result in more than 10000 states.",
            "caused_by": {
              "type": "too_complex_to_determinize_exception",
              "reason": "Determinizing automaton with 64 states and 71 transitions would result in more than 10000 states."
            }
          }
        }
      }
    ]
  },
  "status": 400
}

```

Is there a simpler regex that would satisfy your requirements?

---

<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 6, 2018, 1:28pm UTC](https://discuss.elastic.co/t/kibana-search-regex/139090/3 "2018-08-06T13:28:17Z")

</div>

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