简体   繁体   中英

ElasticSearch index deletion

I'm using Java API to delete old indexes from ElasticSearch.

Client client = searchConnection.client

DeleteIndexResponse delete = client.admin().indices().delete(new DeleteIndexRequest('location')).actionGet();

During deletion cluster goes red for a minute and not indexing new data - reason "missing indices/replicas etc".

How I can tell ElasticSearch that I'm going to delete them to prevent "red state"?

You could use aliases in order to abstract from the real indices underneath. The idea would be to read from an alias and write to an alias instead. That way you can create a new index, swap the write alias to the new index (so that the indexing process is not disrupted) and then delete the old index. Process-wise, it would go like this:

Context: Your current location index has the location_active alias and the indexing process writes to the location_active alias instead of directly to the location index.

Step 1: Create the new location_112015 index

curl -XPUT localhost:9200/location_112015

Step 2: Swap the location_active alias from the "old" location index to the "new" one created in step 1

curl -XPOST 'http://localhost:9200/_aliases' -d '{
    "actions" : [
        { "remove" : { "index" : "location", "alias" : "location_active" } },
        { "add" : { "index" : "location_112015", "alias" : "location_active" } }
    ]
}'

Note that this operation is atomic, so if the indexing process keeps sending new documents to location_active , it will be transparent for it and no docs will be lost, no errors will be raised.

Step 3: Remove the old index

curl -XDELETE localhost:9200/location

Step 4: Rinse and repeat as often as needed

Note: these operations can easily be performed with the Java client library as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM