# Query\_string phrase search with regex

**URL:** <https://discuss.elastic.co/t/query-string-phrase-search-with-regex/366604>\
**Category:** Elasticsearch\
**Created:** [September 16, 2024, 6:58am UTC](https://discuss.elastic.co/t/query-string-phrase-search-with-regex/366604 "2024-09-16T06:58:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonofmun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sonofmun/32/137601_2.png) [@sonofmun](https://discuss.elastic.co/u/sonofmun)\
**Post date:** [September 16, 2024, 6:58am UTC](https://discuss.elastic.co/t/query-string-phrase-search-with-regex/366604/1 "2024-09-16T06:58:12Z")

</div>

I am trying to search for a multi-word phrase using regular expressions. I would prefer to use the FVH because the unified highlighter tends to break highlighting chunks between the words within a phrase. So I would prefer to use a query\_string query instead of a span\_multi query. A phrase search with query\_string without regular expressions functions as expected. So

```auto
{
  "query": {
    "query_string": {
      "query": "\"präsentierten Belege\"", "fields": ["text"]
    }
  }, "highlight": {"fields": {"text": {"type": "fvh"}}}
}

```

returns only documents where the words "präsentierten" and "Belege" occur directly next to each other. But when I try to use regular expressions, like this

```auto
{
  "query": {
    "query_string": {
      "query": "/präsentier.*/ /Beleg.*/", "fields": ["text"]
    }
  }, "highlight": {"fields": {"text": {"type": "fvh"}}}
}

```

I get texts that have either a word starting with "präsentier" or with "Beleg" but not necessarily with both in the same document. If I put AND between the terms then I only get documents with both words but not necessarily in a phrase right next to each other. If I enclose the whole search query with quotation marks, like so:

```auto
{
  "query": {
    "query_string": {
      "query": "\"/präsentier.*/ /Beleg.*/\"", "fields": ["text"]
    }
  }, "highlight": {"fields": {"text": {"type": "fvh"}}}
}

```

then I get no results even though the phrase "präsentierten Belege" exists in the documents and thus should be matched.  
Is this possible without using a span query? If so, how?
