Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 810 Bytes

File metadata and controls

31 lines (24 loc) · 810 Bytes
endpoint indices.exists_alias
lang java
es_version 9.3
client co.elastic.clients:elasticsearch-java:9.3.0

Elasticsearch 9.3 indices.exists_alias endpoint (Java example)

Use client.indices().existsAlias() to check whether an alias exists. The response contains a value() boolean:

var response = client.indices().existsAlias(a -> a.name("shop"));
System.out.println("Alias exists: " + response.value());

Conditional creation

A common pattern is to check for an alias before creating it:

var exists = client.indices().existsAlias(a -> a.name("shop"));

if (!exists.value()) {
    client.indices().putAlias(a -> a.index("products").name("shop"));
    System.out.println("Created alias 'shop'");
} else {
    System.out.println("Alias 'shop' already exists");
}