Как вручную вызвать конечную точку снимка для ElasticSearch, используя JestClient - PullRequest
0 голосов
/ 25 февраля 2019

Я уже использую JestClinet для всех моих операций CRUD на ES на AWS.Теперь я пытаюсь сделать снимок моего ES, как описано в https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html

Вместо использования другого RestClient, мне интересно, могу ли я использовать свой существующий JestClient.

1 Ответ

0 голосов
/ 11 июня 2019

Я не смог найти способ использовать 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;
}
...