Split phrase to search

Hello,

I need to do search mechanism when customer type "My custom phrase" in search then I need to search by:
"My custom phrase"
"My"
"custom"
"phrase"

and in same hierarchic result should be shown.

Should I use custom engine and manually split this sentence and create multiple where or there is a build in mechanism for that ?

You could use a bool query that combines a query for the entire phrase (using the match_phrase query), combined with a query for the individual terms (using a match query). The idea is that documents that contain the exact phrase will get a higher score, because they will match on both clauses.

The query cwould look something like this:

GET _search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "content": "My custom phrase"
        }
      },
      "should": {
        "match_phrase": {
          "content": "My custom phrase"
        }
      }
    }
  }
}

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