# Enterprise-search regex query

**URL:** <https://discuss.elastic.co/t/enterprise-search-regex-query/314926>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [September 22, 2022, 9:01am UTC](https://discuss.elastic.co/t/enterprise-search-regex-query/314926 "2022-09-22T09:01:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![M-Brico](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m-brico/32/111110_2.png) [@M-Brico](https://discuss.elastic.co/u/M-Brico)\
**Post date:** [September 22, 2022, 9:01am UTC](https://discuss.elastic.co/t/enterprise-search-regex-query/314926/1 "2022-09-22T09:01:27Z")

</div>

I’m a bit stuck with and app search regex query for  
"elastic/enterprise-search": "^8.4",

```auto
{
    "query": {
        "bool": {
            "must": {
                "regexp": {
                    "url": {
                        "value": ".*surgery.*",
                        "flags": "ALL"
                    }
                }
            },
            "filter": {
                "term": {
                    "content_type": "standard_page_template"
                }
            }
        }
    }
}

```

this returns results fine  
however

```auto
{
    "query": {
        "bool": {
            "must": {
                "regexp": {
                    "url": {
                        "value": ".*oesophageal-cancer/treatment/surgery.*",
                        "flags": "ALL"
                    }
                }
            },
            "filter": {
                "term": {
                    "content_type": "standard_page_template"
                }
            }
        }
    }
}

```

doesn’t. I’ve tried wrapping  
`(oesophageal-cancer/treatment/surgery)`  
and even escaping the hyphen and slash  
I feel like this is something simple that I’m missing but can’t find direction anywhere (edited)  
this is the PHP code using 8.4 of elastic/enterprise-search

```auto
$path_two = "(advanced-treatment/stents)"; 
 
$searchParams->query = [
    'bool' => [
      'must' => [
        'regexp' => [
          'url' => [
            'value' => '.*' . $path_two,
          ],
        ],
      ],
      'filter' => [
        'term' => [
          'content_type' => 'standard_page_template',
        ],
      ],
    ],
  ];

```

Many thanks, Andrew

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [September 22, 2022, 10:35am UTC](https://discuss.elastic.co/t/enterprise-search-regex-query/314926/2 "2022-09-22T10:35:26Z")

</div>

Replied on slack. Andrew was using an app search engine and taking advantage of the elasticsearch search API. He wanted to perform a regex match on a field. He couldn't due to the field he used was a text type field, a field that is analyzed / tokenized to make it searchable.

I suggested to use instead the enum subfield field provided by the app search engine schema. This worked for his regex.

Joe

---

<div class="post-metadata">

**Author:** ![M-Brico](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m-brico/32/111110_2.png) [@M-Brico](https://discuss.elastic.co/u/M-Brico)\
**Post date:** [September 30, 2022, 8:24am UTC](https://discuss.elastic.co/t/enterprise-search-regex-query/314926/3 "2022-09-30T08:24:49Z")

</div>

Thanks Joe. That worked a treat.

---

<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:** [October 28, 2022, 8:25am UTC](https://discuss.elastic.co/t/enterprise-search-regex-query/314926/4 "2022-10-28T08:25:43Z")

</div>

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