mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Add granular error list to alias action response (#106514)
When an alias action list is posted with must_exist==false, and succeeds only partially, a list of results for each action are now returned. The results contain information about the requested action, indices, and aliases. If must_exist==true, or all actions fail, the call will return a 400 status along with the associated exception.
This commit is contained in:
parent
24aed5c7fe
commit
75228dfd45
26 changed files with 766 additions and 58 deletions
|
@ -121,6 +121,77 @@ POST _aliases
|
|||
// TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\nPUT _data_stream\/logs-my_app-default\n/]
|
||||
// end::alias-multiple-actions-example[]
|
||||
|
||||
[discrete]
|
||||
[[multiple-action-results]]
|
||||
=== Multiple action results
|
||||
|
||||
When using multiple actions, if some succeed and some fail, a list of per-action results will be returned.
|
||||
|
||||
Consider a similar action list to the previous example, but now with an alias `log-non-existing`, which does not yet exist.
|
||||
In this case, the `remove` action will fail, but the `add` action will succeed.
|
||||
The response will contain the list `action_results`, with a result for every requested action.
|
||||
|
||||
[source,console]
|
||||
----
|
||||
POST _aliases
|
||||
{
|
||||
"actions": [
|
||||
{
|
||||
"remove": {
|
||||
"index": "index1",
|
||||
"alias": "logs-non-existing"
|
||||
}
|
||||
},
|
||||
{
|
||||
"add": {
|
||||
"index": "index2",
|
||||
"alias": "logs-non-existing"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
----
|
||||
// TEST[s/^/PUT \/index1\nPUT \/index2\n/]
|
||||
|
||||
The API returns the following result:
|
||||
|
||||
[source,console-result]
|
||||
--------------------------------------------------
|
||||
{
|
||||
"acknowledged": true,
|
||||
"errors": true,
|
||||
"action_results": [
|
||||
{
|
||||
"action": {
|
||||
"type": "remove",
|
||||
"indices": [ "index1" ],
|
||||
"aliases": [ "logs-non-existing" ],
|
||||
},
|
||||
"status": 404,
|
||||
"error": {
|
||||
"type": "aliases_not_found_exception",
|
||||
"reason": "aliases [logs-non-existing] missing",
|
||||
"resource.type": "aliases",
|
||||
"resource.id": "logs-non-existing"
|
||||
}
|
||||
},
|
||||
{
|
||||
"action": {
|
||||
"type": "add",
|
||||
"indices": [ "index2" ],
|
||||
"aliases": [ "logs-non-existing" ],
|
||||
},
|
||||
"status": 200
|
||||
}
|
||||
]
|
||||
}
|
||||
--------------------------------------------------
|
||||
|
||||
Allowing the action list to succeed partially may not provide the desired result.
|
||||
It may be more appropriate to set `must_exist` to `true`, which will cause the entire action
|
||||
list to fail if a single action fails.
|
||||
|
||||
|
||||
[discrete]
|
||||
[[add-alias-at-creation]]
|
||||
=== Add an alias at index creation
|
||||
|
|
|
@ -145,10 +145,16 @@ the alias points to one data stream.
|
|||
+
|
||||
Only the `add` action supports this parameter.
|
||||
|
||||
// tag::alias-options[]
|
||||
`must_exist`::
|
||||
(Optional, Boolean)
|
||||
If `true`, the alias must exist to perform the action. Defaults to `false`. Only
|
||||
the `remove` action supports this parameter.
|
||||
Affects the behavior when attempting to remove an alias which does not exist.
|
||||
If `true`, removing an alias which does not exist will cause all actions to fail.
|
||||
If `false`, removing an alias which does not exist will only cause that removal to fail.
|
||||
Defaults to `false`.
|
||||
// end::alias-options[]
|
||||
+
|
||||
Only the `remove` action supports this parameter.
|
||||
|
||||
// tag::alias-options[]
|
||||
`routing`::
|
||||
|
@ -168,3 +174,51 @@ stream aliases don't support this parameter.
|
|||
Only the `add` action supports this parameter.
|
||||
=====
|
||||
====
|
||||
|
||||
|
||||
|
||||
[role="child_attributes"]
|
||||
[[indices-aliases-api-response-body]]
|
||||
==== {api-response-body-title}
|
||||
|
||||
`acknowledged`::
|
||||
(Boolean)
|
||||
If `true`, the request received a response from the master node within the
|
||||
`timeout` period.
|
||||
|
||||
`errors`::
|
||||
(Boolean)
|
||||
If `true`, at least one of the requested actions failed.
|
||||
|
||||
`action_results`::
|
||||
(Optional, array of objects) Results for each requested action.
|
||||
+
|
||||
.Properties of `action_results` objects
|
||||
[%collapsible%open]
|
||||
====
|
||||
|
||||
`action`::
|
||||
(object)
|
||||
Description of the associated action request.
|
||||
+
|
||||
.Properties of `action` object
|
||||
[%collapsible%open]
|
||||
=====
|
||||
`type`::
|
||||
(string) The type of the associated action, one of `add`, `remove`, or `remove_index`.
|
||||
|
||||
`indices`::
|
||||
(array of strings) List of indices in the associated action.
|
||||
|
||||
`aliases`::
|
||||
(array of strings) List of aliases in the associated action.
|
||||
=====
|
||||
|
||||
`status`::
|
||||
(integer) HTTP status code returned for the action.
|
||||
|
||||
`error`::
|
||||
(Optional, object) Contains additional information about the failed action.
|
||||
+
|
||||
Only present if the action failed.
|
||||
====
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue