I am not able to do a search in a Elasticsearch with character ending/starting with special character. like "123456!"
{
"query": {
"query_string": {
"default_field": "password",
"query": "123456!"
}
}
}
My mappings are
{
"mappings": {
"passwords": {
"properties": {
"date": { "type": "date"},
"password": { "type": "string","index": "not_analyzed"},
}
}
}
}
It is giving me error, what can I do in my search query (or in the mapping), so that special characters will be treated as part of search string ?
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With