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 +}