Enterprise-search regex query

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

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

this returns results fine
however

{
    "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

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

Many thanks, Andrew

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

Thanks Joe. That worked a treat.

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