Restoring indices from snapshot with rename_replacement results in unexpected index name suffix

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

v 1.3.2

Describe the issue:

When I restore an index and use the rename_replacement option I’m getting an unexpected suffix on the index name.

Example restore command:

curl -ksSL -u "$USER_AUTH" -XPOST -H 'Content-Type: application/json' \
https://localhost:9200/_snapshot/log-archive/2021/_restore -d \
'{"rename_pattern": ".*", "rename_replacement": "restored-$0", "indices": "*-foo-2021.04", "ignore_index_settings": ["index.routing.allocation.require.box_type"]}'

Expected restored index name:

restored-server-logs-foo-2021.04

What I get instead (note the restored- suffix):

restored-server-logs-foo-2021.04restored-

I guess this must be happening due to the "rename_replacement": "restored-$0" field, but I don’t understand exactly why it is happening. Any ideas?

Configuration:

S3 storage for snapshots, though not sure if it is relevant.

Relevant Logs or Screenshots:

n/a

Hi, try to change the group reference in the replacement pattern to “$1” instead of “$0” and
rename_pattern.

“$1” refers to the first capture group

{
  "rename_pattern": "^(.*)",
  "rename_replacement": "restored-$1",
  "indices": "*-foo-2021.04",
  "ignore_index_settings": [
    "index.routing.allocation.require.box_type"
  ]
}

Hi, thanks for the response!

Yes that will probably work. However what I wanted to understand is why my original command was not working as expected. Is it a bug in Opensearch?

According to the documentation, $0 should be replaced with the original index name. So I don’t understand what is wrong with my original command?

It could be due to a bug or an implementation quirk in Elasticsearch/OpenSearch.