ES7.6.1 配置x-path后 连接java客户端

装了x-pack插件后,需要填写x-pack相关的设置,

 Settings settings = Settings.builder(). put("xpack.security.user", "elastic:changeme").build();
       client = new PreBuiltXPackTransportClient(settings)
               .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
       elasticsearchTemplate = new ElasticsearchTemplate(client);
       final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
       credentialsProvider.setCredentials(AuthScope.ANY,
               new UsernamePasswordCredentials("elastic", "changeme"));
       restClient = RestClient.builder(new HttpHost("localhost",9200,"http"))
               .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                   @Override
                   public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                       return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                   }
               }).build();

https://discuss.elastic.co/t/none-of-the-configured-nodes-are-available-5-5-0/94951/5

posted @ 2020-05-02 09:16  十点  阅读(790)  评论(0编辑  收藏  举报