elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
70.93k stars 24.9k forks source link

Multi-target syntax doesn't exclude concrete indices anymore when wildcard targets an alias #98077

Open TheRiffRafi opened 1 year ago

TheRiffRafi commented 1 year ago

Elasticsearch Version

8.9.0

Installed Plugins

No response

Java Version

bundled

OS Version

Any

Problem Description

Exclusion in multi-target syntax expects that for:

  1. Indices named missing1, missing2, missing3
  2. With an alias missingalias with mapped index missing3

The following targeting will exclude missing3 from the results:

GET missing*,-missing3/_search

However this has stopped working some time after version 7.17.2 (that is the current older version I am running locally). I ran into it in 7.17.12 up until latest 8.x at the time (8.9.0).

Example in docs:

You can exclude targets using the - character: test*,-test3.

Aliases are resolved after wildcard expressions. This can result in a request that targets an excluded alias. For example, if test3 is an index alias, the pattern test*,-test3 still targets the indices for test3. To avoid this, exclude the concrete indices for the alias instead.

https://www.elastic.co/guide/en/elasticsearch/reference/8.9/api-conventions.html#api-multi-index

In the doc above, it states if test3 is an index alias as the condition, but in my test, test3 (missing3 using my names) is an index, not an alias, and so it should be excluded as it is a concrete index.

Steps to Reproduce

Run these calls on a 7.17.2 version:

Calls ```json PUT missing1 PUT missing2 PUT missing3 POST missing1/_doc { "name": "miki" } POST missing2/_doc { "name": "miki" } POST missing3/_doc { "name": "miki" } POST _aliases { "actions": [ { "add": { "index": "missing3", "alias": "missingalias" } } ] } GET missing*,-missing3/_search ```
Results: ```json ... "hits" : [ { "_index" : "missing1", "_type" : "_doc", "_id" : "R7ZTrokBKaTT_WEROdXK", "_score" : 1.0, "_source" : { "name" : "miki" } }, { "_index" : "missing2", "_type" : "_doc", "_id" : "SLZTrokBKaTT_WERSdUP", "_score" : 1.0, "_source" : { "name" : "miki" } } ] } } ```

Index missing3 is excluded from the search. GOOD!

Now do the same calls on anything above 7.17.12 (or maybe less, sorry didn't have time to test):

Results: ```json ... "hits": { "total": { "value": 3, "relation": "eq" }, "max_score": 1, "hits": [ { "_index": "missing1", "_id": "AXprrokBKqG9nk3QeY0O", "_score": 1, "_source": { "name": "miki" } }, { "_index": "missing2", "_id": "AnprrokBKqG9nk3Qh41D", "_score": 1, "_source": { "name": "miki" } }, { "_index": "missing3", "_id": "A3prrokBKqG9nk3Qj41m", "_score": 1, "_source": { "name": "miki" } } ] } } ```

Index missing3 is not excluded from the search. BAD!

Logs (if relevant)

No response

elasticsearchmachine commented 1 year ago

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