Search Special char support

Hello All,
I have a field called title and it has value

"title" : "Toddler- $kitkat @taste &roll ^yart !here #you %ice ^oops *jam (pot) [beat] pep |old {jet} `egg /lol"

For given input i would like to match any term startswith the given input.
For example If i give #yo or ^oop or %ic it has to return the above document
query_string with field type text works for the above use case if no special char is there but with specical char it is not working. How to solve the usecase.
I used whitespace_analyser for keyword field.
The query not working fine for chars like ^, !, {, [, (, ), }, ] and /
Query used

query_string : {
"fields": ["title.keyword"],
"query": "(* {*"
}

Have you tried using an edge_ngram token filter together with a whitespace tokenizer? That way you would not need to use wildcards in your query string either.

Hi,

In Elasticsearch, certain characters are considered special and need to be escaped with a backslash (\ ). These special characters are: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ / .

you can modify your query to escape the special characters:

{
  "query": {
    "query_string" : {
      "fields": ["title.keyword"],
      "query": "\\(\\* \\{\\*"
    }
  }
}

Regards

1 Like

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