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

Throw exception if index is null or missing when creating an alias #8240

Closed
wants to merge 8 commits into from

Conversation

polyfractal
Copy link
Contributor

Fixes a bug where alias creation would allow null for index name, which thereby applied the alias to all indices. This patch makes the validator throw an exception if the index is null.

Java integration tests and YAML REST tests had to be modified, since they were testing this bug as if it were a real feature.

This is a breaking change, if someone was accidentally relying on this bug.

Fixes #7863, related to old PR #7976

POST /_aliases
{
   "actions": [
      {
         "add": {
            "alias": "empty-alias",
            "index": null
         }
      }
   ]
}
{
   "error": "ActionRequestValidationException[Validation Failed: 1: Alias action [add]: [index] may not be null;]",
   "status": 400
}

The Remove section independently checked the size of indices, but now that
it is being checked at the end of verification it is not needed inside the
Remove clause
The reason this bug wasn't caught by the existing tests is because the old test for nullness
only validated against a cluster which had zero indices.  The null index is translated into "_all",
and since there are no indices, this fails because the index doesn't exist.

However, as soon as you add an index, "_all" resolves and you get the situation described in the
original bug report (but which is not tested by the suite).
assertAcked(admin().indices().prepareAliases().addAlias((String) null, "empty-alias"));
fail("create alias should have failed due to null index");
} catch (ElasticsearchIllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("Validation Failed: 1: Alias action [add]: Property [index] was either missing or null;"));
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps use a "contains" here instead of exact equality? This is less error prone if the wording is slightly tweaked in the future.

@rjernst
Copy link
Member

rjernst commented Oct 27, 2014

LGTM. I left one minor comment.

spalger pushed a commit that referenced this pull request Oct 28, 2014
spalger pushed a commit that referenced this pull request Oct 28, 2014
@polyfractal
Copy link
Contributor Author

This was merged in f5b2dfd

@clintongormley clintongormley changed the title Aliases: Throw exception if index is null or missing when creating an alias Throw exception if index is null or missing when creating an alias Jun 6, 2015
@clintongormley clintongormley added :Data Management/Indices APIs APIs to create and manage indices and templates and removed :Aliases labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>breaking :Data Management/Indices APIs APIs to create and manage indices and templates v1.5.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants