setHttpClientConfigCallback()也在我的代码中显示错误。我正在使用Maven,Eclipse表明(方法setHttpClientConfigCallback((httpClientBuilder) - > {})未定义类型RestClient.Builder)。 我是弹性研究的小伙子。提前谢谢。
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(user,password));
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(host,port,protocol))
.setHttpClientConfigCallback(httpClientBuilder->httpClientBuilder.setDefaultCredentialsProvider));
答案 0 :(得分:0)
我第一次尝试连接时遇到了同样的错误。尝试重写方法而不是使用lambda表达式。错误解决后,将其更改回lambda表达式。希望有所帮助!
示例代码供您参考。
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
RestClientBuilder builder= RestClient.builder(new HttpHost("localhost", 9200, "http")
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder arg0) {
// Your code
return null;
}
});