Can we combine query_string and multi_match queries?

Hi,
I want to create a query for fetching data from elasticsearch which can search for both single and multi-word queries.

For eg, If I search for the keyword : "run" ; it should search for run like Bruno, run, Rune, Irungu etc.

and If I search for keyword : "data structure"; it should return the documents having "data structure" (exact matching).

I have created a query as below:

{
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [ "" ],
"query": "
"+searchTerm+"*"
}
},
{
"multi_match": {
"query": searchTerm,
"operator": "and"
}
}
]
}
}
}

It is working fine when I searched for single word query but not when searched with multiword.

Please correct what I'm doing wrong.

If you want to search for a phrase like data structure, a suitable query type would be Match Phrase Query: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html

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