Restoring Elasticsearch snapshot excluding ilm indices

Viewed 30

I am trying to restore an Elasticsearch snapshot (ES v7.15.2) I am sending a POST request to

http://localhost:9200/_snapshot/repository/snapshot_2022-09-08/_restore?wait_for_completion=true

with body

{
    "indices": "*,-.*"
}

which i think should be all indices not starting with . but I receive the response

{
  "error": {
    "root_cause": [
      {
        "type": "snapshot_restore_exception",
        "reason": "[repository:snapshot_2022-09-08/-s19GVP5Syu7FqsuviPclw] cannot restore index [.ds-ilm-history-5-2022.08.12-000002] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
      }
    ],
    "type": "snapshot_restore_exception",
    "reason": "[repository:snapshot_2022-09-08/-s19GVP5Syu7FqsuviPclw] cannot restore index [.ds-ilm-history-5-2022.08.12-000002] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
  },
  "status": 500
}

So I think the issue is caused by the presence of the ILM index .ds-ilm-history-5-2022.08.12-000002 but I didn't want to restore that anyway and I though it should be excluded by my index specification in the POST body?

Any ideas where its going wrong?

1 Answers

I found that multi-target syntax does not support regexes such as "*,-.*" for aliases:

Aliases are resolved after wildcard expressions. This can result in a request that targets an excluded alias. For example, if test3 is an index alias, the pattern test*,-test3 still targets the indices for test3. To avoid this, exclude the concrete indices for the alias instead.

At the same time, aliases are included in restoring by default:

include_aliases (Optional, Boolean) If true, the request restores aliases for any restored data streams and indices. If false, the request doesn’t restore aliases. Defaults to true.

So I suppose you need to explicitly exclude them if you want your regex to work as expected:

http://localhost:9200/_snapshot/repository/snapshot_2022-09-08/_restore?wait_for_completion=true

{
  "indices": "*,-.*",
  "include_aliases": false
}

(If it is ok for you to ignore them. Otherwise, ofc they should be explicitly excluded as it's suggested in the doc)

Related