Ngram vs wildcard (Using ngrams instead of wildcards)

We are using spring-data-elasticsearch in our Project
we have the autocomplete function for the search textbox. When we type into the search text field, we will fetch suggestions by performing a wild card search with the characters entered in the search box.

    public List<String> fetchSuggestions(String query) {
        QueryBuilder queryBuilder = QueryBuilders
          .wildcardQuery("name", query+"*");

Wouldn't it be better to use ngram/edge-ngram instead of wildcard search? Does ngram/edge-ngram have better performance than wildcard query?

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

Yes. It will most likely perform better. But it will take more time to index documents and more space on disk as more terms will be generated at index time.

That being said, have a look at this feature: Keyword type family | Elasticsearch Guide [7.12] | Elastic