My research mainly pointed me towards two or three solutions.
Firstly, using wildcards:
{
"query": {
"wildcard": {
"name": "*searchTerm*"
}
}
}
However, the drawback is that wildcards can be slow.
Secondly, the option to use a query string:
{
"query":{
"query_string":{
"default_field":"name",
"query":"*searchTerm*"
}
}
}
This method also seems slow, possibly due to the leading wildcard.
I believe there's a third way involving the use of an n-gram tokenizer and match query, by setting the minimum to 3 and the maximum to a larger number.
"match": {
"name": "searchTerm"
}
Will this approach work? In this case, does the searchTerm also go through the analyzer? If yes, is there any way to prevent this? I don't want to return results where the name fields are equal to "sear" just because the searchTerm has been tokenized.
What's the recommended approach? Am I overlooking something? Ideally, the query should:
a) Be search performant.
b) Allow for easy toggling between case sensitivity and insensitivity.