Hi everyone,
TL;DR : the _aliases
API throw error trying to remove index saying it doesn't exist but it does.
I'm using the aliases API to swap two indices behind an alias in a single atomic operation. I'm following the example provided in the "Multiple Actions" section of the Aliases documentation.
In addition to swapping the indices, I would like to delete the index removed from the alias, still in a "single atomic operation" fashion using the remove_index
action.
Here is the query I came up with :
POST _aliases
{
"actions": [
{
"remove": {
"index": "backing_index-1",
"alias": "testalias"
}
},
{
"add": {
"index": "backing_index-2",
"alias": "testalias"
}
},
{
"remove_index": {
"index": "backing_index-1"
}
}
]
}
The first two actions are similar to those presented in the documentation.
However, I got this error after executing the query :
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index [backing_index-1]",
"index_uuid": "_na_",
"index": "backing_index-1"
}
],
"type": "index_not_found_exception",
"reason": "no such index [backing_index-1]",
"index_uuid": "_na_",
"index": "backing_index-1"
},
"status": 404
}
This error is caused by the last action (remove_index
). I've tried the same query without it and it works (but doesn't delete the old index, as excepted).
Here are all the steps you can follow to try to reproduce the error :
## Creating indices
POST backing_index-1/_doc/1
{"value": "The query reached backing_index-1"}
POST backing_index-2/_doc/1
{"value": "The query reached backing_index-2"}
## Creating the alias
POST _aliases
{
"actions": [
{
"add": {
"index": "backing_index-1",
"alias": "testalias"
}
}
]
}
## This should return "The query reached backing_index-1"
GET testalias/_doc/1?filter_path=_source.value
## Swapping indices and deleting the old one
POST _aliases
{
"actions": [
{
"remove": {
"index": "backing_index-1",
"alias": "testalias"
}
},
{
"add": {
"index": "backing_index-2",
"alias": "testalias"
}
},
{
"remove_index": {
"index": "backing_index-1"
}
}
]
}
The workaround I've found is doing this instead, but, as you can see, the "single atomic operation" is completely lost here :
## Swaping indices
POST _aliases
{
"actions": [
{
"remove": {
"index": "backing_index-1",
"alias": "testalias"
}
},
{
"add": {
"index": "backing_index-2",
"alias": "testalias"
}
}
]
}
## Deleting the old one
POST _aliases
{
"actions": [
{
"remove_index": {
"index": "backing_index-1"
}
}
]
}
Is there something I'm missing ?
I'm running Elasticsearch 8.6.0 on premise by the way.
Thanks for reading !