Java 启用 https 后客户端调用弹性搜索

Java rest client call elastic search after enable https

各位,我正在使用 elasticsearch 6.8.22,我需要为它启用 https 我已经设置了elasticsearch的安全并且可以连接到https://localhost:9200/_cat/indices?v,它需要用户登录,然后我已经设置了用户密码并且可以登录elasticsearch

但是当我使用java rest client连接elastic search时,抛出这样的错误

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

我使用的是RestHighLevelClient,elastic jar版本是6.5.4,elasticsearch的认证已经安装到我的java客户端,我想是因为我需要将elasticsearch用户名和密码添加到java client , 有没有人知道这个或者我们是否可以在 java client 调用 elasticsearch 时跳过授权用户?

这是我的弹性搜索 https 设置

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

通过以下方式解决了问题

  1. /bin 运行 cmd 中:elasticsearch-setup-passwords 交互式设置 elastic search 用户密码
  2. 应用以下更改 https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.16/_basic_authentication.html