Elatisearch match_phrase_prefix query, with exact prefix match

442 Views Asked by At

I have a match_phrase_prefix query, which works as expected. But when the users passes any special characters at the end of the keyword, ES ignores these characters, and still returns the result. query{ match_phrase_prefix:{ content: { query: searchTerm } } }

I am using this query to search for prefix. If i pass a term like overflow@#@#!! ES is returning me all the results with the word overflow in it. But instead i want to make an exact prefix match, where the special characters are not ignored. The search term could be of multiple words as well stack overflow search. How could i make ES search of prefix_match without ignoring the special_chars.

1

There are 1 best solutions below

0
Triet Doan On

You can use keyword analyzer when defining your query.

{
  "query": {
    "match_phrase_prefix": {
      "content": {
        "query": "overflow@#@#!!",
        "analyzer": "keyword"
      }
    }
  }
}