Christophe
Christophe

Reputation: 2200

Fuzzy suggestions in elasticsearch 6

I'm in the process of upgrading to elasticsearch 6.0 in my java webapp.

Before I was using CompletionSuggestionFuzzyBuilder to build suggestions but with the newest version this class is gone. I've found that I can create a MaMatchQueryBuilder that will use fuzziness to get results :

MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("user", "kimchy");
matchQueryBuilder.fuzziness(Fuzziness.AUTO); 
matchQueryBuilder.prefixLength(3); 
matchQueryBuilder.maxExpansions(10); 

but I can't use it with suggestions. So I'm looking for a way to use fuzzy suggestions.

Upvotes: 0

Views: 189

Answers (1)

Christophe
Christophe

Reputation: 2200

I think I've found the way to do that. Here is a solution :

SearchResponse suggestRequestBuilder = elasticClient.prepareSearch(index)
        .suggest(new SuggestBuilder()
                     .addSuggestion(
                        "suggestionsFuzzy",
                        SuggestBuilders.completionSuggestion("myField")
                            .prefix(suggestRequest, Fuzziness.AUTO).size(10)
                     )
        ).get();

Upvotes: 1

Related Questions