How can I know if an index is exist or not?
I am using co.elastic.clients 8.6.2 in Java
below is my code
String index = "test"+ date;
try {
ElasticsearchClient client = elasticsearchConfig.getClient();
SearchResponse<Object> searchResponse = null;
searchResponse = client.search(s -> s.index(index)
.sort(sort -> sort.field(f -> f.field("creationDateTime").order(SortOrder.Asc)))
.size(DEFAULT_SEARCH_RESPONSE_SIZE), Object.class);
for (Hit<Object> hit : searchResponse.hits().hits()) {
Object data = hit.source();
Map<?, ?> map = (Map<?, ?>) data;
JSONObject jsonObject = new JSONObject(map);
array.put(jsonObject);
}
client._transport().close();
} catch (Exception e) {
e.printStackTrace();
}
Basically I want to check the index is exist or not before I start searching
I found this way might be work
client.indices().exists(ExistsRequest);
But i dont know how to use ExistsRequest,can someone tell me how to use it?