TwTw
TwTw

Reputation: 547

Add alias to index and remove index using JEST API in Java

I'm using jest api for connect to elastic Search I'm wonder if there is a way in Jest to add alias to index with existing index name and delete the index in same operation. like this, but via Jest api:

POST /_aliases
{
    "actions" : [
        { "add":  { "index": "new_index", "alias": "index_1" } },
        { "remove_index": { "index": "index_1" } }  
    ]
}

Upvotes: 1

Views: 1141

Answers (3)

kartik sama
kartik sama

Reputation: 9

In the Java API client 8.x version you can achieve reindexing using alias as follows with no downtime as follows,

PutAliasRequest putAliasRequest = new PutAliasRequest.Builder()
                .index("new_index_name")
                .name("alias_name")
                .build();
elasticsearchClient.indices().putAlias(putAliasRequest);

DeleteAliasRequest deleteAliasRequest = new DeleteAliasRequest.Builder()
                .index("old_index_name")
                .name("alias")
                .build();
elasticsearchClient.indices().deleteAlias(deleteAliasRequest);

Upvotes: 1

Amit
Amit

Reputation: 32386

Looks like there is no API in JEST to do this in the same API, but you can use two different API, one to add an alias and another to remove an alias.

Please have a source code of alias mapping(abstract class) which is implemented by Add alias mapping and remove alias mapping classes.

As mentioned by @Val, it's been dormant() and doesn't support the latest versions of elasticsearch(not greater than 6 which is the end of life as well), so better to migrate to the official Java client if you can.

Upvotes: 1

Val
Val

Reputation: 217564

It is not yet implement in Jest. It looks like Jest has been "dormant" to say the least...

You should consider leveraging the official High-Level Java REST client instead as it provides support for doing exactly what you need.

Upvotes: 1

Related Questions