Exclude option not working while taking snapshot

Versions OpenSearch 1.2.4 and OpenSearch 2.9.0

Describe the issue:

In my OpenSearch cluster, I have these two indices.

curl localhost:9200/_cat/indices?v

health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open new-index Jqk6CK-MSF-vCdCjMDk52w 1 1 6 0 3.9kb 3.9kb
yellow open .test 95jdNc8vRkqZySldr8x0SQ 1 1 0 0 208b 208b

While taking snapshot of indices stored inside OpenSearch, I want to exclude .test index.
As per Take snapshots, I used - to exclude the index.

curl -X PUT “http://localhost:9200/_snapshot/test-repo/1?pretty” -H ‘Content-Type: application/json’ -d’
{
“indices”: [
“-.test”
],
“ignore_unavailable”: false,
“include_global_state”: false,
“partial”: false
}’

But, snapshot creation failed with error index_not_found_exception.

Error

{
“error” : {
“root_cause” : [
{
“type” : “index_not_found_exception”,
“reason” : “no such index [-.test]”,
“index” : “-.test”,
“resource.id” : “-.test”,
“resource.type” : “index_or_alias”,
“index_uuid” : “na
}
],
“type” : “index_not_found_exception”,
“reason” : “no such index [-.test]”,
“index” : “-.test”,
“resource.id” : “-.test”,
“resource.type” : “index_or_alias”,
“index_uuid” : “na
},
“status” : 404
}

Tried adding * along with - like below.

curl -X PUT “http://localhost:9200/_snapshot/test-repo/1?pretty” -H ‘Content-Type: application/json’ -d’
{
“indices”: [
“-.test*”
],
“ignore_unavailable”: false,
“include_global_state”: false,
“partial”: false
}’

Now, snapshot creation passed. But other index (new-index) is not considered for snapshot.

curl -XGET "http://localhost:9200/_snapshot/test-repo/_all?pretty"

{
“snapshots” : [
{
“snapshot” : “1”,
“uuid” : “rUfh4Nd6S_qNTJ6OmFmksQ”,
“version_id” : 135238227,
“version” : “1.2.4”,
“indices” : ,
“data_streams” : ,
“include_global_state” : false,
“state” : “SUCCESS”,
“start_time” : “2023-08-02T07:06:09.095Z”,
“start_time_in_millis” : 1690959969095,
“end_time” : “2023-08-02T07:06:09.095Z”,
“end_time_in_millis” : 1690959969095,
“duration_in_millis” : 0,
“failures” : ,
“shards” : {
“total” : 0,
“failed” : 0,
“successful” : 0
}
}
]
}

This - character is working fine (ignoring the indices starting with -) for restore operation.

Can anyone help me with solving this?

After adding * as separate index pattern, it’s working as expected.

curl -XPUT “http://localhost:9200/_snapshot/test-repo/1?pretty” -H ‘Content-Type: application/json’ -d’
{
“indices”: [
“*”,
“-.test”
],
“ignore_unavailable”: false,
“include_global_state”: false,
“partial”: false
}’

curl -XGET "http://localhost:9200/_snapshot/test-repo/_all?pretty"

{
“snapshots” : [
{
“snapshot” : “1”,
“uuid” : “jM1pwppgSaeGcyWW2_oilw”,
“version_id” : 135238227,
“version” : “1.2.4”,
“indices” : [
“test-index”
],
“data_streams” : ,
“include_global_state” : false,
“state” : “SUCCESS”,
“start_time” : “2023-08-02T07:48:18.653Z”,
“start_time_in_millis” : 1690962498653,
“end_time” : “2023-08-02T07:48:18.653Z”,
“end_time_in_millis” : 1690962498653,
“duration_in_millis” : 0,
“failures” : ,
“shards” : {
“total” : 2,
“failed” : 0,
“successful” : 2
}
}
]
}