【问题标题】:AWS ElasticSearch/OpenSearch not connecting from javaAWS ElasticSearch/OpenSearch 未从 java 连接
【发布时间】:2021-12-24 17:36:08
【问题描述】:

我使用亚马逊 aws 网站上的一个简单示例连接到 opensearch 索引。 这是示例源https://docs.aws.amazon.com/opensearch-service/latest/developerguide/request-signing.html#request-signing-java。 我的节点的健康状态是黄色并且它是打开的

黄色打开我的索引

错误信息

Exception in thread "main" java.net.ConnectException
    at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227)
    at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1256)
    at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1231)
    at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:587)
    at com.amazonaws.lambda.demo.AWSElasticsearchServiceClient.main(AWSElasticsearchServiceClient.java:41)
Caused by: java.net.ConnectException
    at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:168)
    at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:561)
    at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:822)
    at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:192)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
    at java.lang.Thread.run(Unknown Source) ```



    private static String region = "us-west-1";
    private static String domainEndpoint = "<my-index...amazon.com>"; // e.g. https://search-mydomain.us-west-1.es.amazonaws.com
    private static String index = "my-index";
    private static String type = "_doc";
    private static String id = "1";
    static final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();

 ```   public static void main(String[] args) throws IOException {
        RestHighLevelClient searchClient = searchClient(serviceName, region);

        // Create the document as a hash map
        Map<String, Object> document = new HashMap<>();
        document.put("title", "Walk the Line");
        document.put("director", "James Mangold");
        document.put("year", "2005");

        // Form the indexing request, send it, and print the response
        IndexRequest request = new IndexRequest(index, type, id).source(document);
        IndexResponse response = searchClient.index(request, RequestOptions.DEFAULT);
        System.out.println(response.toString());
    }

    // Adds the interceptor to the OpenSearch REST client
    public static RestHighLevelClient searchClient(String serviceName, String region) {
        AWS4Signer signer = new AWS4Signer();
        signer.setServiceName(serviceName);
        signer.setRegionName(region);
        HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor(serviceName, signer, credentialsProvider);
        return new RestHighLevelClient(RestClient.builder(HttpHost.create(domainEndpoint)).setHttpClientConfigCallback(hacb -> hacb.addInterceptorLast(interceptor)));
    }

【问题讨论】:

  • 我希望端点不是“”。它应该是您的 opensearch 域的端点,可以在 aws 的 opensearch 仪表板的“一般信息”中找到。
  • 你说得对,我不想把端点放在这里

标签: java amazon-web-services elasticsearch opensearch


【解决方案1】:

试试this example。我尝试了同样的方法,它对我来说效果很好。我没有为证书做任何事情,因为我按照 AWS 演示示例创建了域。

希望这是您正在寻找的...

【讨论】:

    猜你喜欢
    • 2022-11-05
    • 2021-12-27
    • 1970-01-01
    • 2021-08-11
    • 2022-01-27
    • 2018-05-04
    • 2021-01-22
    • 1970-01-01
    • 2021-12-19
    相关资源
    最近更新 更多