Skip to content

Commit f1a4551

Browse files
Implement Exclude Patterns for Snapshot- and Repository Names in Get Snapshots API (#77308)
It's in the title. Adds support for exclude patterns combined with wildcard requests similar to what we support for index names.
1 parent 0d54332 commit f1a4551

File tree

7 files changed

+405
-94
lines changed

7 files changed

+405
-94
lines changed

docs/reference/snapshot-restore/apis/get-repo-api.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ GET /_snapshot/my_repository
4646
`<repository>`::
4747
(Optional, string)
4848
Comma-separated list of snapshot repository names used to limit the request.
49-
Wildcard (`*`) expressions are supported.
49+
Wildcard (`*`) expressions are supported including combining wildcards with exclude patterns starting with `-`.
5050
+
5151
To get information about all snapshot repositories registered in the
5252
cluster, omit this parameter or use `*` or `_all`.

docs/reference/snapshot-restore/apis/get-snapshot-api.asciidoc

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ Use the get snapshot API to return information about one or more snapshots, incl
6060
`<repository>`::
6161
(Required, string)
6262
Comma-separated list of snapshot repository names used to limit the request.
63-
Wildcard (`*`) expressions are supported.
63+
Wildcard (`*`) expressions are supported including combining wildcards with exclude patterns starting with `-`.
6464
+
6565
To get information about all snapshot repositories registered in the
6666
cluster, omit this parameter or use `*` or `_all`.
6767

6868
`<snapshot>`::
6969
(Required, string)
70-
Comma-separated list of snapshot names to retrieve. Also accepts wildcards (`*`).
70+
Comma-separated list of snapshot names to retrieve.
71+
Wildcard (`*`) expressions are supported including combining wildcards with exclude patterns starting with `-`.
7172
+
7273
* To get information about all snapshots in a registered repository, use a wildcard (`*`) or `_all`.
7374
* To get information about any snapshots that are currently running, use `_current`.
@@ -151,8 +152,8 @@ exclusive with using the `after` parameter. Defaults to `0`.
151152
`slm_policy_filter`::
152153
(Optional, string)
153154
Filter snapshots by a comma-separated list of SLM policy names that snapshots belong to. Also accepts wildcards (`\*`) and combinations
154-
of wildcards followed by exclude patterns starting in `-`. For example, the pattern `*,-policy-a-\*` will return all snapshots except
155-
for those that were created by an SLM policy with a name starting in `policy-a-`. Note that the wildcard pattern `*` matches all snapshots
155+
of wildcards followed by exclude patterns starting with `-`. For example, the pattern `*,-policy-a-\*` will return all snapshots except
156+
for those that were created by an SLM policy with a name starting with `policy-a-`. Note that the wildcard pattern `*` matches all snapshots
156157
created by an SLM policy but not those snapshots that were not created by an SLM policy. To include snapshots not created by an SLM
157158
policy you can use the special pattern `_none` that will match all snapshots without an SLM policy.
158159

@@ -546,4 +547,84 @@ The API returns the following response:
546547
// TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.snapshots.0.start_time_in_millis/]
547548
// TESTRESPONSE[s/"end_time": "2020-07-06T21:55:18.129Z"/"end_time": $body.snapshots.0.end_time/]
548549
// TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.snapshots.0.end_time_in_millis/]
549-
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshots.0.duration_in_millis/]
550+
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshots.0.duration_in_millis/]
551+
552+
The following request returns information for all snapshots with prefix `snapshot` in the `my_repository` repository,
553+
except for the one named `snapshot_3`
554+
555+
[source,console]
556+
----
557+
GET /_snapshot/my_repository/snapshot*,-snapshot_3?sort=name
558+
----
559+
560+
The API returns the following response:
561+
562+
[source,console-result]
563+
----
564+
{
565+
"snapshots": [
566+
{
567+
"snapshot": "snapshot_1",
568+
"uuid": "dKb54xw67gvdRctLCxSket",
569+
"repository": "my_repository",
570+
"version_id": <version_id>,
571+
"version": <version>,
572+
"indices": [],
573+
"data_streams": [],
574+
"feature_states": [],
575+
"include_global_state": true,
576+
"state": "SUCCESS",
577+
"start_time": "2020-07-06T21:55:18.129Z",
578+
"start_time_in_millis": 1593093628850,
579+
"end_time": "2020-07-06T21:55:18.129Z",
580+
"end_time_in_millis": 1593094752018,
581+
"duration_in_millis": 0,
582+
"failures": [],
583+
"shards": {
584+
"total": 0,
585+
"failed": 0,
586+
"successful": 0
587+
}
588+
},
589+
{
590+
"snapshot": "snapshot_2",
591+
"uuid": "vdRctLCxSketdKb54xw67g",
592+
"repository": "my_repository",
593+
"version_id": <version_id>,
594+
"version": <version>,
595+
"indices": [],
596+
"data_streams": [],
597+
"feature_states": [],
598+
"include_global_state": true,
599+
"state": "SUCCESS",
600+
"start_time": "2020-07-06T21:55:18.130Z",
601+
"start_time_in_millis": 1593093628851,
602+
"end_time": "2020-07-06T21:55:18.130Z",
603+
"end_time_in_millis": 1593094752019,
604+
"duration_in_millis": 1,
605+
"failures": [],
606+
"shards": {
607+
"total": 0,
608+
"failed": 0,
609+
"successful": 0
610+
},
611+
}
612+
],
613+
"total": 2,
614+
"remaining": 0
615+
}
616+
----
617+
// TESTRESPONSE[s/"uuid": "dKb54xw67gvdRctLCxSket"/"uuid": $body.snapshots.0.uuid/]
618+
// TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.snapshots.1.uuid/]
619+
// TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.snapshots.0.version_id/]
620+
// TESTRESPONSE[s/"version": <version>/"version": $body.snapshots.0.version/]
621+
// TESTRESPONSE[s/"start_time": "2020-07-06T21:55:18.129Z"/"start_time": $body.snapshots.0.start_time/]
622+
// TESTRESPONSE[s/"start_time": "2020-07-06T21:55:18.130Z"/"start_time": $body.snapshots.1.start_time/]
623+
// TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.snapshots.0.start_time_in_millis/]
624+
// TESTRESPONSE[s/"start_time_in_millis": 1593093628851/"start_time_in_millis": $body.snapshots.1.start_time_in_millis/]
625+
// TESTRESPONSE[s/"end_time": "2020-07-06T21:55:18.129Z"/"end_time": $body.snapshots.0.end_time/]
626+
// TESTRESPONSE[s/"end_time": "2020-07-06T21:55:18.130Z"/"end_time": $body.snapshots.1.end_time/]
627+
// TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.snapshots.0.end_time_in_millis/]
628+
// TESTRESPONSE[s/"end_time_in_millis": 1593094752019/"end_time_in_millis": $body.snapshots.1.end_time_in_millis/]
629+
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshots.0.duration_in_millis/]
630+
// TESTRESPONSE[s/"duration_in_millis": 1/"duration_in_millis": $body.snapshots.1.duration_in_millis/]

0 commit comments

Comments
 (0)