-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Snapshot restore requests allow you to restore data stream alias with conflicting name #80972
Description
Elasticsearch version (bin/elasticsearch --version):
Version: 8.1.0-SNAPSHOT, Build: default/tar/e38cadb5283feeea06f09d555dbe47fb1d5e8b39/2021-11-22T22:35:22.825882Z, JVM: 17.0.1
OS version (uname -a if on a Unix-like system):
Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
Description of the problem including expected versus actual behavior:
I expect ES to reject snapshot restore requests that restore a data stream alias with the same name as an existing data stream or index.
However, ES currently accepts these requests. This cluster now has a data stream/index and alias with the same name. A user may not be sure which resource a search request targeting the name will hit.
Steps to reproduce:
- Register a snapshot repository
PUT /_snapshot/my_repository
{
"type": "fs",
"settings": {
"location": "my_backup_location"
}
}
- Create a data stream.
POST logs-my_app-default/_doc
{
"@timestamp": "2099-05-06T16:21:15.000Z"
}
- Add a
logsalias to the data stream.
POST _aliases
{
"actions": [
{
"add": {
"index": "logs-my_app-default",
"alias": "logs"
}
}
]
}
- Create a snapshot containing the data stream and its alias
PUT _snapshot/my_repository/my_snapshot?wait_for_completion=true
- Delete the data stream. This also deletes the alias.
DELETE _data_stream/logs-my_app-default
- Create another data stream with same name as the deleted alias (
logs).
PUT _index_template/my-index-template
{
"index_patterns": ["logs"],
"data_stream": { },
"priority": 500
}
POST logs/_doc
{
"@timestamp": "2099-05-07T16:21:15.000Z"
}
- Restore the data stream and
logsalias from the snapshot.
POST /_snapshot/my_repository/my_snapshot/_restore?wait_for_completion=true
{
"indices": "logs-my_app-default",
"include_aliases": true
}
I expected this to return an error due to a conflict between the restored logs
alias and the pre-existing logs data stream. However, the request was
accepted, and both resources now exist.
Retrieve the logs data stream:
GET _data_stream/logs
Retrieve the logs alias:
GET _alias/logs
A search on logs only hits the logs data stream:
GET logs/_search
However, a search on log* hits both the alias and the data stream:
GET log*/_search