AWS Elasticsearch:签署elasticsearch-rest-high-level-client发出的请求

时间:2018-04-10 07:09:24

标签: elasticsearch aws-elasticsearch

我们正在使用elasticsearch-rest-high-level-client与AWS Elasticsearch进行通信。

但是,正如我们所知,我们需要使用AWS凭证签署请求。我知道课程 string query = "d=bla bla bla"; string encoded = System.Web.HttpUtility.UrlEncode( query, System.Text.Encoding.UTF8 ); ,但我不知道如何将其与AWS4Signer一起使用。

1 个答案:

答案 0 :(得分:0)

从aws documentation

public static RestHighLevelClient esClient(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(aesEndpoint)).setHttpClientConfigCallback(hacb -> hacb.addInterceptorLast(interceptor)));
}