如何使用JestClient手动为ElasticSearch调用快照终结点

时间:2019-02-25 09:32:55

标签: jest aws-elasticsearch elasticsearch-snapshot

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

我想知道是否可以使用现有的JestClinet。而不是使用另一个RestClient

1 个答案:

答案 0 :(得分: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;
}