We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
以下是7版本的代码,可是换成8网上找不到最新版本的教程。麻烦实现参考以下。谢谢
public class ElasticsearchClient { private static final String INDEX_NAME = "my_index"; private static final String FIELD_NAME = "suggestion_field"; private RestHighLevelClient client; public ElasticsearchClient(String hostname, int port) { client = new RestHighLevelClient( RestClient.builder(new HttpHost(hostname, port, "http"))); } public List<String> getSuggestions(String input) throws IOException { SearchRequest searchRequest = new SearchRequest(INDEX_NAME); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); CompletionSuggestionBuilder completionSuggestionBuilder = new CompletionSuggestionBuilder(FIELD_NAME); completionSuggestionBuilder.prefix(input); completionSuggestionBuilder.size(5); // Limit the number of suggestions SuggestBuilder suggestBuilder = new SuggestBuilder(); suggestBuilder.addSuggestion("suggest", completionSuggestionBuilder); searchSourceBuilder.suggest(suggestBuilder); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); Suggest suggest = searchResponse.getSuggest(); CompletionSuggestion suggestion = suggest.getSuggestion("suggest"); List<String> suggestions = suggestion .getEntries() .stream() .flatMap(e -> e.getOptions().stream()) .map(option -> option.getText().string()) .collect(Collectors.toList()); return suggestions; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
以下是7版本的代码,可是换成8网上找不到最新版本的教程。麻烦实现参考以下。谢谢
The text was updated successfully, but these errors were encountered: