# Rename pattern of restoring snapshot API has an unexpected behavior

**URL:** <https://discuss.elastic.co/t/rename-pattern-of-restoring-snapshot-api-has-an-unexpected-behavior/313512>\
**Category:** Elasticsearch\
**Tags:** snapshot-and-restore\
**Created:** [September 2, 2022, 7:39am UTC](https://discuss.elastic.co/t/rename-pattern-of-restoring-snapshot-api-has-an-unexpected-behavior/313512 "2022-09-02T07:39:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kent010341](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@kent010341](https://discuss.elastic.co/u/kent010341)\
**Post date:** [September 2, 2022, 7:39am UTC](https://discuss.elastic.co/t/rename-pattern-of-restoring-snapshot-api-has-an-unexpected-behavior/313512/1 "2022-09-02T07:39:08Z")

</div>

I'm using Elasticsearch 7.17.4, running with Docker.

I have a snapshot containing an index called `metricbeat-7.12.0-2022.09.01`, and I want it to be renamed with a prefix or a suffix.

However, like the image below, its name becomes `prefix_metricbeat-7.12.0-2022.09.01_suffixprefix__suffix` after restoring.

 ![prefix and suffix](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b84b4eaa4d8a0574e58bd1fc1de2e7b3118c80a1.png)

This is for testing, so there's only one index being restored. What I want is to add the prefix and suffix to any index being restored, so I use `*` for `indices` and `(.*)` for `rename_pattern`.

I don't know what's wrong with it, and I hope someone can tell me how to fix it.

Thanks.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [September 4, 2022, 9:42am UTC](https://discuss.elastic.co/t/rename-pattern-of-restoring-snapshot-api-has-an-unexpected-behavior/313512/2 "2022-09-04T09:42:51Z")

</div>

You want `(.+)` rather than `(.*)`. Elasticsearch uses `Matcher#replaceAll` to compute the renamed index, and this will behave in unexpected ways if your pattern matches an empty string.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [September 4, 2022, 9:53am UTC](https://discuss.elastic.co/t/rename-pattern-of-restoring-snapshot-api-has-an-unexpected-behavior/313512/3 "2022-09-04T09:53:46Z")

</div>

I opened [Rename-on-restore behaves weirdly if `rename_pattern` matches an unanchored empty string · Issue #89792 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/89792) to report this bug.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 2, 2022, 9:54am UTC](https://discuss.elastic.co/t/rename-pattern-of-restoring-snapshot-api-has-an-unexpected-behavior/313512/4 "2022-10-02T09:54:27Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
