elasticsearchhttpsrest-clientelasticsearch-x-packjava-client

Java rest client call elastic search after enable https


everyone , I am using elasticsearch 6.8.22 and I need to enable the https for it I have done setting of secure the elasticsearch and can connect to https://localhost:9200/_cat/indices?v , it require user login , then I already set the user password and can login the elastic search enter image description here

but when I use java rest client to connect elastic search , it throw such error

{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication token for REST request

I am using RestHighLevelClient and the elastic jar version is 6.5.4, the certification of elastic search already install into my java client, I think it's because I need to add the elasticsearch user and password into java client , is there anyone knows about this or whether we can skip to authorize the user when java client call elastic search ?

Here is my elastic search https setting

xpack.security.enabled : true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: D:/App/elasticsearch-6.8.22/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: D:/App/elasticsearch-6.8.22/config/certs/elastic-certificates.p12

xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: D:/App/elasticsearch-6.8.22/config/certs/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: D:/App/elasticsearch-6.8.22/config/certs/elastic-certificates.p12

Solution

  • resolved the problem by following way

    1. in the <es_folder>/bin run cmd : elasticsearch-setup-passwords interactive to set elastic search user password
    2. apply following changes https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.16/_basic_authentication.html