Reputation: 3522
I my index lets say I have field field named "full_name". I'm doing following query:
{
"query":{
"bool":{
"must":[
{
"wildcard":{
"full_name":"ab*"
}
}
]
}
},
"size":50
}
And it return values that fits exactly, for example:
"full_name" : "abrakadabra"
But also I receive things like this:
"full_name" : "kad abra"
Wildacrd "ab*" fits word "abra" and therefore I have "full_name" : "kad abra" . How can I avoid it, and search only for first word prefix?
Upvotes: 1
Views: 199
Reputation: 30163
Standard analyzer, which is applied by default to strings, generates a term for each word. So, "kad abra" is indexed as two terms "kad" and "abra", and your query finds the second term. If you want to search full_name always as a phrase, you should index it with custom analyzer with keyword tokenizer and lowercase filter. Alternatively, you can just index this field as not_analyzed if case is meaningful in your terms.
Upvotes: 3