Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3760e8c
Add granular error list to alias action response
parkertimmins Mar 19, 2024
dbb590a
Add response body description to aliases API docs
parkertimmins Mar 20, 2024
e701c5e
Update docs/changelog/106514.yaml
parkertimmins Mar 20, 2024
c001f79
Add new transport version and fix broken tests
parkertimmins Mar 20, 2024
818e397
Formatting - need to call spotlessApply
parkertimmins Mar 20, 2024
1e77a38
Skip AliasActionResult yaml rest tests before 8.14
parkertimmins Mar 21, 2024
a49c318
Merge branch 'main' into alias-remove-must-exist
parkertimmins Mar 21, 2024
f541cbf
Fix broken compilation after merge from main
parkertimmins Mar 21, 2024
6e6aba0
Pass on actual response rather than default value
parkertimmins Mar 22, 2024
d15732d
Clarify confusing phrase in docs
parkertimmins Mar 22, 2024
c481858
Refactor main alias action result loop
parkertimmins Mar 22, 2024
f189e0c
Add info from request to alias action response
parkertimmins Mar 26, 2024
824ef69
Update docs with action info added in last commmit
parkertimmins Mar 26, 2024
de8c0f2
Merge branch 'main' into alias-remove-must-exist
parkertimmins Mar 26, 2024
927ca25
Merge branch 'main' into alias-remove-must-exist
parkertimmins Mar 26, 2024
26b9896
Change success+error msg to status+error object
parkertimmins Apr 1, 2024
1d41b67
Fix yaml rest tests
parkertimmins Apr 1, 2024
b1451ce
update docs with status + error obj
parkertimmins Apr 1, 2024
5ec76ea
Merge branch 'main' into alias-remove-must-exist
parkertimmins Apr 1, 2024
b04efea
Merge branch 'main' into alias-remove-must-exist
parkertimmins Apr 2, 2024
91472a4
Revert originalIndices logic to use indices
parkertimmins Apr 2, 2024
e3d5ce5
Add resolved index names to alias action result
parkertimmins Apr 3, 2024
d3c9654
Merge branch 'main' into alias-remove-must-exist
parkertimmins Apr 3, 2024
481ee9d
Fix tests to expect index name resolution
parkertimmins Apr 3, 2024
eba3361
Add serialization tests for IndicesAliasesResponse
parkertimmins Apr 3, 2024
02e225f
Test serialization Ack <-> IndicesAliasesResponse
parkertimmins Apr 3, 2024
fea757b
add javadoc
parkertimmins Apr 3, 2024
0dd10ba
Asserts on IndiceAliasesResponse construction
parkertimmins Apr 7, 2024
a9a1931
Add exception class to equality/hashcode
parkertimmins Apr 7, 2024
3860789
spotlessApply
parkertimmins Apr 7, 2024
6a86c40
Remove incorrect assert
parkertimmins Apr 7, 2024
68b497a
Merge branch 'main' into alias-remove-must-exist
parkertimmins Apr 7, 2024
8f4c88a
Merge branch 'main' into alias-remove-must-exist
parkertimmins Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/reference/alias.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,66 @@ 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.

// tag::alias-multiple-actions-result-example[]
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": "remove",
"success": false,
"error": "aliases_not_found_exception"
},
{
"action": "add",
"success": true
}
]
}
--------------------------------------------------

Allowing the action list to succeed partially may not provide the desired result.
It may be more appropriate to use set `must_exist` to `true`, which will cause the entire action
list to fail if a single action fails.

// end::alias-multiple-actions-example[]

[discrete]
[[add-alias-at-creation]]
=== Add an alias at index creation
Expand Down
10 changes: 8 additions & 2 deletions docs/reference/indices/aliases.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,84 @@
indices.get_alias:
name: this-does-not-exist*
- is_false: ds-first.aliases.my-alias
---
"Action Results with multiple matching aliases":
- skip:
version: " - 7.13.99"
reason: "data streams aliases are available from 7.14.0"
features: allowed_warnings
- do:
allowed_warnings:
- "index template [my-template] has index patterns [log-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
indices.put_index_template:
name: my-template
body:
index_patterns: [ log-* ]
template:
settings:
index.number_of_replicas: 0
data_stream: { }
- do:
indices.create_data_stream:
name: log-foobar
- is_true: acknowledged
- do:
indices.update_aliases:
body:
actions:
- add:
index: log-foobar
aliases: test_alias1
- remove:
index: log-foobar
aliases: test_non_existing
must_exist: false
- is_true: errors
- length: { action_results: 2 }
- match: { action_results.0.success: true }
- match: { action_results.0.action: add }
- match: { action_results.1.success: false }
- match: { action_results.1.action: remove }
- match: { action_results.1.error: aliases_not_found_exception }
---
"Single action result per action":
- skip:
version: " - 7.13.99"
reason: "data streams aliases are available from 7.14.0"
features: allowed_warnings
- do:
allowed_warnings:
- "index template [my-template] has index patterns [log-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
indices.put_index_template:
name: my-template
body:
index_patterns: [ log-* ]
template:
settings:
index.number_of_replicas: 0
data_stream: { }
- do:
indices.create_data_stream:
name: log-test-1
- do:
indices.create_data_stream:
name: log-test-2
- is_true: acknowledged
- do:
indices.update_aliases:
body:
actions:
- add:
index: log-test-*
aliases: test_alias1
- remove:
index: log-test-*
aliases: test_non_existing
must_exist: false
- is_true: errors
- length: { action_results: 2 }
- match: { action_results.0.success: true }
- match: { action_results.0.action: add }
- match: { action_results.1.success: false }
- match: { action_results.1.action: remove }
- match: { action_results.1.error: aliases_not_found_exception }
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,86 @@
- remove_index:
index: test_index
must_exist: true
---
"Partial success with must_exist == false":
- do:
indices.create:
index: test_index
- do:
indices.update_aliases:
body:
actions:
- add:
index: test_index
aliases: test_alias1
- remove:
index: test_index
aliases: test_non_existing
must_exist: false
- is_true: errors
- match: { action_results.0.success: true }
- match: { action_results.0.action: add }
- match: { action_results.1.success: false }
- match: { action_results.1.action: remove }
- match: { action_results.1.error: aliases_not_found_exception }
---
"Partial success with must_exist == null (default)":
- do:
indices.create:
index: test_index
- do:
indices.update_aliases:
body:
actions:
- add:
index: test_index
aliases: test_alias1
- remove:
index: test_index
aliases: test_non_existing
- is_true: errors
- match: { action_results.0.success: true }
- match: { action_results.0.action: add }
- match: { action_results.1.success: false }
- match: { action_results.1.action: remove }
- match: { action_results.1.error: aliases_not_found_exception }
---
"No action_results field if all actions successful":
- do:
indices.create:
index: test_index
- do:
indices.update_aliases:
body:
actions:
- add:
index: test_index
aliases: test_alias1
- is_false: errors
- match: { action_results: null }
---
"Single result per input action":
- do:
indices.create:
index: test_index1
- do:
indices.create:
index: test_index2
- do:
indices.update_aliases:
body:
actions:
- add:
index: test_index*
aliases: test_alias1
- remove:
index: test_index*
aliases: test_non_existing
- length: { action_results: 2 }
- is_true: errors
- match: { action_results.0.success: true }
- match: { action_results.0.action: add }
- match: { action_results.1.success: false }
- match: { action_results.1.action: remove }
- match: { action_results.1.error: aliases_not_found_exception }

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.elasticsearch.action.admin.indices.alias;

import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse.AliasActionResult;
import org.elasticsearch.cluster.ack.ClusterStateUpdateRequest;
import org.elasticsearch.cluster.metadata.AliasAction;

Expand All @@ -18,8 +19,11 @@
public class IndicesAliasesClusterStateUpdateRequest extends ClusterStateUpdateRequest<IndicesAliasesClusterStateUpdateRequest> {
private final List<AliasAction> actions;

public IndicesAliasesClusterStateUpdateRequest(List<AliasAction> actions) {
private final List<IndicesAliasesResponse.AliasActionResult> actionResults;

public IndicesAliasesClusterStateUpdateRequest(List<AliasAction> actions, List<AliasActionResult> actionResults) {
this.actions = actions;
this.actionResults = actionResults;
}

/**
Expand All @@ -28,4 +32,8 @@ public IndicesAliasesClusterStateUpdateRequest(List<AliasAction> actions) {
public List<AliasAction> actions() {
return actions;
}

public List<AliasActionResult> getActionResults() {
return actionResults;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public byte value() {
return value;
}

public String getFieldName() {
return fieldName;
}

public static Type fromValue(byte value) {
return switch (value) {
case 0 -> ADD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.internal.ElasticsearchClient;
import org.elasticsearch.index.query.QueryBuilder;

Expand All @@ -21,7 +20,7 @@
*/
public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder<
IndicesAliasesRequest,
AcknowledgedResponse,
IndicesAliasesResponse,
IndicesAliasesRequestBuilder> {

public IndicesAliasesRequestBuilder(ElasticsearchClient client) {
Expand Down
Loading