Avoiding wildcard searches
Wildcard searches are useful when we don't know the exact search text and know only certain parts of the text. So, in that case, we will provide some text plus a wildcard character to get all the matches to partial text and also the text against the wildcard characters, which can be numbers of characters or can be without any character limit, which again depends on the type of the wildcard we have used. Take a look at the following example where we want to search for the name of a blogger, but we do not remember the exact name and only knows that it starts with pa
and ends with l
:
GET /_search {"query":{"wildcard":{"name":"pa*l"}}}
On executing this search, Elasticsearch will return all the results with the name starting with pa
and ending with l
, such as paul
. This is a good feature and quite helpful in those situations where we do not know the exact search text.
Now, let's return to the problem part and understand why we should avoid wildcards in certain situations...