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

POST _aliases remove_index does not support wildcard exclusion #35882

Closed
exe-dealer opened this issue Nov 25, 2018 · 3 comments
Closed

POST _aliases remove_index does not support wildcard exclusion #35882

exe-dealer opened this issue Nov 25, 2018 · 3 comments
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates

Comments

@exe-dealer
Copy link

Elasticsearch version (bin/elasticsearch --version):
Version: 6.5.1, Build: default/tar/8c58350/2018-11-16T02:22:42.182257Z, JVM: 11.0.1

OS version (uname -a if on a Unix-like system):
Linux 15484e2ef940 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2+deb8u5 (2017-09-19) x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:

PUT test-1
PUT test-2
POST _aliases
{
  "actions": [{
    "remove_index": {
      "index": "test-*,-test-1"
    }
  }]
}

Last command produces

{
  "error" : {
    "root_cause" : [
      {
        "type" : "index_not_found_exception",
        "reason" : "no such index",
        "resource.type" : "index_or_alias",
        "resource.id" : "test-*,-test-1",
        "index_uuid" : "_na_",
        "index" : "test-*,-test-1"
      }
    ],
    "type" : "index_not_found_exception",
    "reason" : "no such index",
    "resource.type" : "index_or_alias",
    "resource.id" : "test-*,-test-1",
    "index_uuid" : "_na_",
    "index" : "test-*,-test-1"
  },
  "status" : 404
}

But I expect the last command to successfully delete test-2 and keep test-1 because doc says that remove_index is just like Delete Index
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#CO181-3
And DELETE test-*,-test-1 works as expected

@colings86 colings86 added the :Data Management/Indices APIs APIs to create and manage indices and templates label Nov 26, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@lipsill
Copy link
Contributor

lipsill commented Jan 21, 2019

I had a look at this and the issue seems to be that _aliases support two separate fields index and indices. If an index is provided, ES will take the expression as is (without splitting it by ,), and then try to resolve it. Hence ES cannot find the expression test-*,-test-1.
If "index":"test-*" is provided, both test-1 and test-2 are deleted. If you want to delete only test-2, please use "indices" : ["test-*", "-test-1"]

To delete test-2 using _aliases endpoint

POST _aliases
{
  "actions": [{
    "remove_index": {
      "indices": ["test-*", "-test-1"]
    }
  }]
}

To delete test-1 and test-2

POST _aliases
{
  "actions": [{
    "remove_index": {
      "index": "test-*"
    }
  }]
}
POST _aliases
{
  "actions": [{
    "remove_index": {
      "index": "test-*,-test-1"
    }
  }]
}

results in

"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "test-*,-test-1",

This difference is also documented in Multiple Indices Note

Single index APIs such as the Document APIs and the single-index alias APIs do not support multiple indices.

@exe-dealer @colings86 I think that _aliases works as documented.

Another option is to change the alias API

  • split the index by comma - this will align it with the other APIs that support multiple indices
  • split the index by comma and deprecate indices to avoid any further confusion

@exe-dealer
Copy link
Author

I would never guess that "indices" accepts wildcards and even negation.
"indices": ["test-*", "-test-1"] solves my problem, thank you @lipsill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates
Projects
None yet
Development

No branches or pull requests

4 participants