1

我已经JestClinet在 AWS 上的 ES 上使用我的所有 CRUD 操作。现在我正在尝试按照 https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html中的描述对我的 ES 进行快照

而不是使用另一个RestClient,我想知道我是否可以使用我现有的JestClient.

4

1 回答 1

0

我找不到使用 JestClient 的方法,使用 RestClient 如下:

String snapshotPath = "/_snapshot/my_repot/snapshot1?wait_for_completion=true";
HttpEntity entity = new NStringEntity("{}", ContentType.APPLICATION_JSON);
Header header = new BasicHeader("Content-Type", "application/json");

try{
  final AWSSigner awsSigner = new AWSSigner(awsAuthProvider, region, "es",
    () -> LocalDateTime.now(ZoneOffset.UTC));
  final AWSSigningRequestInterceptor requestInterceptor = new AWSSigningRequestInterceptor(awsSigner);

  RestClient restClient = RestClient.builder(HttpHost.create(elasticUrl))
        .setRequestConfigCallback(rcc -> rcc.setSocketTimeout(15 * 60 * 1000))
        .setHttpClientConfigCallback(hacb -> hacb.addInterceptorLast(requestInterceptor))
        .setMaxRetryTimeoutMillis(15 * 60 * 1000)
        .build();
  response = restClient.performRequest("PUT", snapshotPath, Collections.emptyMap(), entity, header);

  if(200 == response.getStatusLine().getStatusCode()) {     
    return true;
  }else {       
    return false;
  }
}catch(IOException e) {
  return false;
}
于 2019-06-11T06:37:57.390 回答