What's the recommended method for checking if a string is part of a field?

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.

bump

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.