Can anyone please tell me how can i write wildcard queries with multiple fields in elasticsearch i have searched a lot on this but some one told me to use query string or multi match but the problem in my case is query string is not working for me my code is given below for a single field wildcard query if anyone know anything about this please share some light on this
"query": {
"wildcard" : { "places_area1.city.raw_wildcard" : last_wildcard_string }
}
UPDATE Mappings
"settings": {
"index": {
"analysis": {
"analyzer": {
"synonym_wildcard": {
"tokenizer": "whitespace",
"filter": ["filter_wildcard"]
},
"synonym_term": {
"tokenizer": "keyword",
"filter": ["filter_term"]
},
"simple_wildcard": {
"tokenizer": "whitespace"
}
},
"filter": {
"filter_term": {
"tokenizer": "keyword", // here you have to write this only for tokenizer keyword but not for whitespace
"type": "synonym",
"synonyms_path": "synonyms.txt",
},
"filter_wildcard": {
"type": "synonym",
"synonyms_path": "synonyms.txt",
}
}
}
}
},
mappings : {
places_area1: {
properties:{
area1 : {"type" : "string", "index": "analyzed", "analyzer": "simple_wildcard"},
city : {"type" : "string", "fields": {
"raw": {
"type": "string",
"analyzer": "synonym_term"
},
"raw_wildcard": {
"type": "string",
"analyzer": "synonym_wildcard"
}
} },
}
}
}
}
Thank You In Advance
Are you looking for something like this?
{
"query": {
"query_string": {
"fields": ["title", "description", "state"],
"query": "Ban*",
"lowercase_expanded_terms": false
}
}
}
Why do you need "lowercase_expanded_terms": false
?
Since you are using keyword
and whitespace
tokenizer, word Bangalore is indexed as Bangalore and while using query string wildcard
Ban*
is lowercased because it is default setting and ES is looking for words starting with ban and hence it does not find Bangalore. You could also resolve this by adding lowercase
filter to your mappings
Also it was working previously because you did not specify any analzyer and by default ES uses standard analzyer
and it internally uses lowercase token filter
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