My use case requires to query for our elastic search domain with trailing wildcards. I wanted to get your opinion on the best practices of handling such wildcards in the queries.
Do you think adding the following clauses is a good practice for the queries:
"query" : {
"query_string" : {
"query" : "attribute:postfix*",
"analyze_wildcard" : true,
"allow_leading_wildcard" : false,
"use_dis_max" : false
}
}
I've disallowed leading wildcards since it is a heavy operation. However I wanted to how good is analyzing wildcard for every query request in the long run. My understanding is, analyze wildcard would have no impact if the query doesn't actually have any wildcards. Is that correct?
If you have the possibility of changing your mapping type and index settings, the right way to go is to create a custom analyzer with an edge-n-gram token filter that would index all prefixes of the
attribute
field.Then, when you index a document, the
attribute
field value (e.g.)postfixing
will be indexed as the following tokens:p
,po
,pos
,post
,postf
,postfi
,postfix
,postfixi
,postfixin
,postfixing
.Finally, you can then easily query the
attribute
field for thepostfix
value using a simplematch
query like this. No need to use an under-performing wildcard in a query string query.