How I escape Unicode characters using a quer_string query? For example, my documents consist the following data:
{
"title":"@Sachin#$Tendular%^^*bestplayer*(tiger)!god~~ofcricket"
}
I am using the query_string query in the following way:
{
"query": {
"query_string": {
"fields": ["title"],
"query": "*@Sachin#$Tendular%^^*bestplayer*(tiger)!god~~ofcricket*"
}
}
}
I am not getting any result so How I will escape the character to get a result?
You can use \ (backslash) to escape characters. Beware that JSON also uses backslash as escape character and you will need to put in two backslashes like this:
{
"query": {
"query_string": {
"fields": ["title"],
"query": "\"@Sachin#$Tendular%\\^\\^\\*bestplayer\\*\\(tiger\\)\\!god\\~\\~ofcricket\""
}
}
}
Adding quotes around the text turns it into a single phrase query.
If you want to escape unicode characters, you can use the \u notation:
{
"query": {
"query_string": {
"fields": ["title"],
"query": "\u00e5"
}
}
}
See: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/query-dsl-query-string-query.html for more information.