elasticsearch,Java,Amazon Web Services,Spring Boot,elasticsearch" /> elasticsearch,Java,Amazon Web Services,Spring Boot,elasticsearch" />

带有AWS ElasticSearch的Java RestHighLevelClient

带有AWS ElasticSearch的Java RestHighLevelClient,java,amazon-web-services,spring-boot,elasticsearch,Java,Amazon Web Services,Spring Boot,elasticsearch,我想知道这里是否有人使用RestHighLevelClient连接到AWS ElasticSearch。不确定这是否是AWS ElasticSearch支持的。我当前每次尝试连接时都会收到ConnectionClosedException 以下是我所拥有的: public SearchResponse getQuery(){ RestHighLevelClient client = new RestHighLevelClient( RestClient.build

我想知道这里是否有人使用RestHighLevelClient连接到AWS ElasticSearch。不确定这是否是AWS ElasticSearch支持的。我当前每次尝试连接时都会收到ConnectionClosedException

以下是我所拥有的:

public SearchResponse getQuery(){
    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(new HttpHost("localhost", 4430, "http")));
    SearchRequest searchRequest = new SearchRequest("msglog-dev-2018.05.21");
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(QueryBuilders.matchAllQuery());
    searchRequest.source(searchSourceBuilder);
    SearchResponse searchResponse = null;
    try{
        searchResponse =client.search(searchRequest);
    }catch(IOException e){
        e.printStackTrace();
    }
    return searchResponse;
}
我得到的错误是

org.apache.http.ConnectionClosedException: Connection closed
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.endOfInput(HttpAsyncRequestExecutor.java:347)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:261)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)                                                             
                                                                   ...........

是的,我们使用RHLC和AWS。这是一个可以让你朝正确方向前进的例子。这演示了一个直接调用(这可能与更多的读者相关)——但通过调整连接参数(主机、端口、协议)的设置,它可以很容易地适应您的隧道需求

此示例对版本6.3.x(YMMV)有效:
是的,我们将RHLC与AWS一起使用。这是一个可以让你朝正确方向前进的例子。这演示了一个直接调用(这可能与更多的读者相关)——但通过调整连接参数(主机、端口、协议)的设置,它可以很容易地适应您的隧道需求

此示例对版本6.3.x(YMMV)有效:

但您正在代码中连接到localhost实例?!是的,我的ElasticSearch当前正在通过隧道连接到该端口,但您正在代码中连接到localhost实例?!是的,我的ElasticSearch当前正在被隧道传输到该端口。如果有帮助,只需在client.search(searchRequest,RequestOptions.DEFAULT)中添加RequestOptions.DEFAULT即可;对于上面的版本6.7.x n,将Elasticsearch的用户名和密码放在awshelpful上,只需在client.search中添加RequestOptions.DEFAULT(searchRequest,RequestOptions.DEFAULT);对于以上版本6.7.x n,将Elasticsearch的用户名和密码放在aws的何处
private static final String HOST = "your-es-endpoint.es.amazonaws.com";
private static final int PORT = 443;
private static final String PROTOCOL = "https";

private static final RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(HOST, PORT, PROTOCOL)));

public static void getESDocs() {
    try {
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        sourceBuilder.query(QueryBuilders.matchAllQuery());   // adjust search logic here
        SearchRequest searchRequest = new SearchRequest("your-index-here");
        searchRequest.source(sourceBuilder);
        final SearchResponse searchResponse = client.search(searchRequest);

        /* process results here... */

        }
    } catch (Exception e) {
         /* handle connection/proc error here */
    } finally {
         client.close();    // example to release driver resource (see doc link)
    }
}