From 85592627d621c4102610d9faeced9f7b3830b411 Mon Sep 17 00:00:00 2001 From: LiWeiJie <3491909454@qq.com> Date: Tue, 27 Aug 2024 10:57:08 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=BF=9E=E6=8E=A5=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/config/es/ElasticSearchConfig.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/qiwenshare/file/config/es/ElasticSearchConfig.java b/src/main/java/com/qiwenshare/file/config/es/ElasticSearchConfig.java index 6f6e0ee..5b9f69c 100644 --- a/src/main/java/com/qiwenshare/file/config/es/ElasticSearchConfig.java +++ b/src/main/java/com/qiwenshare/file/config/es/ElasticSearchConfig.java @@ -4,8 +4,17 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.json.jackson.JacksonJsonpMapper; import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.rest_client.RestClientTransport; +import java.util.Base64; +import org.apache.http.Header; import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.message.BasicHeader; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,8 +22,9 @@ import org.springframework.context.annotation.Configuration; public class ElasticSearchConfig { @Bean public ElasticsearchClient elasticsearchClient(){ - RestClient client = RestClient.builder(new HttpHost("localhost", 9200,"http")).build(); - ElasticsearchTransport transport = new RestClientTransport(client,new JacksonJsonpMapper()); - return new ElasticsearchClient(transport); + RestClient client = RestClient.builder(new HttpHost("117.73.12.23", 49200, "http")) + .setDefaultHeaders(new Header[]{new BasicHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("elastic:Y123456a".getBytes()))}) + .build(); + return new ElasticsearchClient(new RestClientTransport(client,new JacksonJsonpMapper())); } -} \ No newline at end of file +}