23 Mayıs 2023 Salı

Eski ElasticSearchHighLevel IndicesClient Sınıfı

exists metodu
Örnek
Şöyle yaparız
GetIndexRequest request = new GetIndexRequest(props.getIndex().getName());
boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);

if (!exists) {
  CreateIndexRequest indexRequest = new CreateIndexRequest(props.getIndex().getName());
  indexRequest.settings(Settings.builder()
       .put("index.number_of_shards", props.getIndex().getShard())
       .put("index.number_of_replicas", props.getIndex().getReplica())
  );

  CreateIndexResponse createIndexResponse = client.indices()
    .create(indexRequest, RequestOptions.DEFAULT);
  if (createIndexResponse.isAcknowledged()&& createIndexResponse.isShardsAcknowledged()) {
      log.info("{} index created successfully", props.getIndex().getName());
  } else {
    log.debug("Failed to create {} index", props.getIndex().getName());
  }
}

Hiç yorum yok:

Yorum Gönder