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

/_aliases remove action ignores must_exist when alias is missing #94478

Closed
lastnico opened this issue Mar 10, 2023 · 3 comments · Fixed by #106514
Closed

/_aliases remove action ignores must_exist when alias is missing #94478

lastnico opened this issue Mar 10, 2023 · 3 comments · Fixed by #106514
Assignees
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates Team:Data Management Meta label for data/management team

Comments

@lastnico
Copy link

lastnico commented Mar 10, 2023

Elasticsearch Version

8.6.0

Installed Plugins

No response

Java Version

bundled

OS Version

Linux 5.19.0-35-generic #36-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 3 18:36:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

If I try to perform a single "remove" action with "must_exist": false on the /_aliases endpoint, I still receive an HTTP 404 response with "type": "aliases_not_found_exception".

This seems to contradict documentation of the /aliases API

must_exist
(Optional, Boolean) If true, the alias must exist to perform the action. Defaults to false. Only the remove action supports this parameter.

Steps to Reproduce

[ ] Create index new_index

PUT /new_index
{}

[ ] Try to remove a missing some_alias on new_index index

POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "new_index",
        "alias": "some_alias",
        "must_exist": false
      }
    }
  ]
}

[ ] This will lead to the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "aliases_not_found_exception",
        "reason": "aliases [some_alias] missing",
        "resource.type": "aliases",
        "resource.id": "some_alias"
      }
    ],
    "type": "aliases_not_found_exception",
    "reason": "aliases [some_alias] missing",
    "resource.type": "aliases",
    "resource.id": "some_alias"
  },
  "status": 404
}

Logs (if relevant)

No response

@lastnico lastnico added >bug needs:triage Requires assignment of a team area label labels Mar 10, 2023
@stu-elastic
Copy link
Contributor

"must_exist": true stops other actions in alias requests if the alias does not exist.

So other_alias is not created in this case.

POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "new_index",
        "alias": "some_alias",
        "must_exist": true
      }
    },
    {
      "add": {
        "index": "new_index",
        "alias": "other_alias"
      }
    }
  ]
}

However, the same request with "must_exist": false (or omitted, as it's the default), other_alias is created.

So it seems to be working as intended, but I agree the 404 is confusing when there is only one action and it's a remove with "must_exist": false. Sending over to the Data Management team for their thoughts.

@stu-elastic stu-elastic added :Data Management/Other and removed needs:triage Requires assignment of a team area label labels Mar 10, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label Mar 10, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@stu-elastic stu-elastic added :Data Management/Indices APIs APIs to create and manage indices and templates and removed :Data Management/Other Team:Data Management Meta label for data/management team labels Mar 10, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label Mar 10, 2023
@parkertimmins parkertimmins self-assigned this Mar 12, 2024
parkertimmins added a commit to parkertimmins/elasticsearch that referenced this issue Mar 13, 2024
Changes behavior of removing as alias that does not exist, with
must_exist argument set to false, or left as the default null.
Previously returned 404 with AliasNotFoundException; now returns 200.

Fixes elastic#94478
@parkertimmins
Copy link
Contributor

parkertimmins commented Mar 13, 2024

After some thought, I think we should continue to return 404 on removal on non-existing aliases if must_exist==false. Rather than making the change in this ticket, the docs should be updated to indicate that the must_exist argument affects the atomicity of applying a list of actions. Additionally, the phrase "single atomic operation" in the docs, should probably be updated to clarify that the operation is only atomic if must_exist==true.

This is my reasoning:

  • DELETE /some_index/_alias/non_existing_alias returns 404, as it should.
  • The following list of actions with a single remove should be expected to behave the same as the above DELETE . More pragmatically, these share the same removal code, and it would be better to keep them as the same code.
POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "some_index",
        "alias": "non_existing_alias"
      }
    }
  ]
}
  • Though it might make sense to return 200 if must_exist==false, this is the default case, so returning 200 for must_exist==false also requires returning 200 in the above case where the must_exist argument is absent.
  • Silently failing in the default case seems undesired.

parkertimmins added a commit to parkertimmins/elasticsearch that referenced this issue Mar 19, 2024
This commit does the following:
* When an alias action list succeeds partially a list of results for each
  action are returned. This will only occur is must_exist==false
* Use same exception for removal of missing aliases whether must_exist
  is true or false.

Closes elastic#94478
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates Team:Data Management Meta label for data/management team
Projects
None yet
6 participants