search with special characters in elasticsearch
Since your password
field is not_analyzed
(good!), try to do an exact match by surrounding 123456!
with double quotes:
{
"query": {
"query_string": {
"default_field": "password",
"query": "\"123456!\""
}
}
}
Another way of doing this is to set the keyword
analyzer in your query_string
query (but make sure to escape the !
because it's a reserved character (for the NOT
operator)
{
"query": {
"query_string": {
"default_field": "password",
"query": "123456\!",
"analyzer": "keyword"
}
}
}
In addition to Vals answer, one could also escape the query
using the escape
parameter:
{
"query": {
"query_string": {
"default_field": "password",
"query": "123456!",
"analyzer": "keyword",
"escape": true
}
}
}