elastic match_phrase_prefix set order of words

347 Views Asked by At

Unable to find a clean way to do this type of query -- is there a way to specify that these prefixes return only results with the word prefixes in order? Such that a valid return would be Alpha Beta and Beta Alpha would not return?

"query": {
"bool": {
  "must": [
    {
      "match_phrase_prefix": {
        "search_name": "Al"
      }
    },
    {
      "match_phrase_prefix": {
        "search_name": "Be"
      }
    }
  ]
}

},

1

There are 1 best solutions below

1
Ali Hashemi On

If you have indexed a keyword-type version of the field, you can do this:

"query": {
   "bool": {
     "must": [
       {
         "match_phrase_prefix": {
           "search_name.keyword": "Al"
         }
       },
       {
         "match_phrase_prefix": {
           "search_name.keyword": "Be"
         }
       }
     ]
   }
}