Search for exact phrase in not_analyzed (keyword) field

Hey there,

I like to search for an exact phrase of words in my documents. To have a document be part of the search results the phrase should be somewhere in the searched fields.

My fields have type "keyword" as I don't want to have any analyzing done before and the search should search the original string.

Let's assume the field value of some document is "ElasticSearch is a popular search engine".
The following searches should return/not return the document.

"ElasticSearch" => return
"ElasticSearch is" => return
"popular search" => return
"popular engine" => not return
"is popular" => not return

I tried the following query, all of them without success. Either no results will be returned or too many. It seems like query_string indeed splits for whitespace even if the doc for my understand says it doesn't ("Whitespaces are not considered operators..."):

"query_string": {
   "fields": ["search_fields.name.raw"],
    "query": "*ElasticSearch is*"
}

"query_string": {
   "fields": ["search_fields.name.raw"],
    "query": "*\"ElasticSearch is\"*"
}

(I know wildcards . at the beginning are not performant - I'll tackle that later).

The question was already asked here like 7 years ago but there was no working answer posted:
http://elasticsearch-users.115913.n3.nabble.com/Wildcards-in-exact-phrase-in-query-string-search-td4020826.html

What could also be relevant: I don't know all the fields before so I use dynamic_templates and multi_match/query_string to search through multiple fields inside an object.

I'd appreciate if someone could give me hints how to solve that.

Thanks
Christian

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