Let us see how to check if an index exists in OpenSearch via Java client.
OpenSearch has a Java SDK that can be used to communicate with OpenSearch natively.
We can use the indices()
exists()
method with the ExistsRequest to check if the index with the given name is present or not. It returns a BooleanResponse
which indicates only the presence.
BooleanResponse response = openSearchClient.indices().exists(ExistsRequest.of(s -> s.index("sample-index"))); response.value(); // true or false