Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multiple aliases in _cat/aliases api #23698

Merged
merged 14 commits into from Apr 28, 2017
Expand Up @@ -46,7 +46,7 @@ public RestAliasAction(Settings settings, RestController controller) {
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ?
new GetAliasesRequest(request.param("alias")) :
new GetAliasesRequest(request.param("alias").split(",")) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider changing the parameter from alias to aliases as it is misleading to pack a list in alias.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use Strings.commaDelimitedListToStringArray here as we do in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't knew about this class. I will use it.

new GetAliasesRequest();
getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));

Expand Down
5 changes: 3 additions & 2 deletions docs/reference/cat/alias.asciidoc
Expand Up @@ -54,5 +54,6 @@ alias4 test1 - 2 1,2
The output shows that `alias2` has configured a filter, and specific routing
configurations in `alias3` and `alias4`.

If you only want to get information about a single alias, you can specify
the alias in the URL, for example `/_cat/aliases/alias1`.
If you only want to get information about specific aliases, you can specify
the aliases in comma-delimited format as a URL parameter, e.g.,
/_cat/aliases/aliases/alias1,alias2.
Expand Up @@ -126,6 +126,48 @@
- match:
$body: / (^|\n)test_2 .+ \n/

---
"Multiple alias names":

- do:
indices.create:
index: test

- do:
indices.create:
index: test2
- do:
indices.create:
index: test3

- do:
indices.put_alias:
index: test
name: foo

- do:
indices.put_alias:
index: test2
name: bar
- do:
indices.put_alias:
index: test3
name: baz

- do:
cat.aliases:
name: foo,bar

- match:
$body: /(^|\n)foo\s+test /

- match:
$body: /(^|\n)bar\s+test2 /

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this test should add a third index, and a third alias, and not request that alias (as you've already done) just so that we can be sure that a non-requested alias is not returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do that

- match:
$body: /(^|\n)[^bar\s+test3] /
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can and should make a stronger assertion here. We can request only the alias and index fields, request that the cat API sort the output on the index field, and then assert the exact expected output:

foo test
bar test2



---
"Column headers":

Expand Down