elastic / elasticsearch-py

Official Python client for Elasticsearch
https://ela.st/es-python
Apache License 2.0
37 stars 1.18k forks source link

Python Module - es.indices.exists doesn't support wildcards as it should #2708

Closed mbeaufre closed 2 weeks ago

mbeaufre commented 2 weeks ago

In the documentation: Documentation of exists function

It is written that exists method supports wildcards ('*'). My screenshot aim to prove that it doesn't, in version 8.14 and lilkely later versions, since it was already written in the documentation for release 8.14.0 it had the support for wildcards.

Image

Just for the context: This index doesn't exists, neither does a variation of its name.

pquentin commented 2 weeks ago

Hello! Thank you for your question. In the future, I would prefer Markdown code blocks rather than screenshots of code, as they are easier to work with, even when working in a notebook.

If I understand correctly, what you're seeing is:

If yes, then that's not evidence of the wildcard support failing. I believe you don't have an index named ...-data-2024-11-12 (which is why the first call returns False), but you probably have an index named like ...-data-2024-11-12-001, which is why the two other calls return True.

To confirm that theory you can use es.indices.get(index="...-data-2024-11-12*") (docs) and you will see which indices match.

pquentin commented 2 weeks ago

I just saw your edit, and can confirm the behavior. Looking into it more, thank you.

pquentin commented 2 weeks ago

Digging into it a bit more, I realized that you need to use allow_no_indices=False to get the behavior you want. The default behavior is definitely confusing, but was kept this way to not break backward compatibility and be consistent with the Get Index API that also returns 200 OK when no indices match with a wildcard.

es.indices.exists(index="...-data-2024-11-12*", allow_no_indices=False)
pquentin commented 2 weeks ago

I'm going to go ahead and close this, but I would still be happy to know if that fixed your problem or not. And I can always reopen if needed.

mbeaufre commented 2 weeks ago

Hello !

Sorry about the non-markdown format, noted for the next time. Thanks for your help, it worked.

I read the doc of the exists function but didn't understand that allow_no_indices did what I wanted.

Merci !