我正在阅读这些文档以从 Elastic 的高级 JAVA REST 客户端创建一个弹性搜索索引。它似乎跳过了使用我的弹性云帐户进行身份验证的步骤。有人可以指出我的相关文档吗?
我启动了我的弹性搜索实例并将端点 URL 复制到我的客户端代码中。
我最初有连接错误,现在没有。只有身份验证错误。所以,我很确定我正在使用正确的端点 URL 进行连接,并且需要以某种方式进行身份验证 - 也许使用标头。
现在,我看到了这个错误:
Elasticsearch 异常 [type=security_exception, reason=action [indices:data/write/index] 需要身份验证]
我可以使用以下命令从 Postman 毫无问题地查看我的 Elastic Search 部署的端点:GET https://:@d97215aee2.us-east-1.aws.found.io:9243
我还可以使用 Postman 的此命令创建索引... PUT https://elastic:4YQIMXfoSZ9mXPgY1fj7T5BU@d97218f74f6d48489b355dd7d665aee2.us-east-1.aws.found.io:9243/。然而,我不能从 Java 代码中做同样的事情。
这是我的 Java 代码的状态。这几乎是这些教程页面中的代码。
import java.io.IOException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
@Path("/elasticsearch")
public class ElasticSearchService {
@POST
public void createElasticIndex() throws IOException {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("d9<deleted a bunch of characters for privacy>7d665aee2.us-east-1.aws.found.io", 9243, "https")));
IndexRequest request = new IndexRequest(
"posts",
"doc",
"1");
String jsonString = "{" +
"\"user\":\"kimchy\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elasticsearch\"" +
"}";
request.source(jsonString, XContentType.JSON);
client.close();
}
}
我还尝试使用我们的用户名和密码更新 URL 地址,正如这篇文章所建议的那样:ElasticSearch authentication error with ElasticCloud?
本质上,我像这样更新了我的网址......
RestClient.builder(
new HttpHost(
"<my user name>:<my password>@d97218<hidden characters>d665aee2.us-east-1.aws.found.io",
9243, "https")));
这对我不起作用。我猜这个人没有使用新的 Elastic High Level REST 客户端。我收到了这个错误:
org.glassfish.jersey.server.internal.process.MappableException: java.io.IOException: :@d97265aee2.us-east-1.aws.found.io: IPv6 地址无效