Python Elasticsearch client: Unable to get data when * included in index name

I have written the following code in python to get data from my Elastic deployment:

from elasticsearch import Elasticsearch
client = Elasticsearch(<endpoint>,api_key=(<API key ID>,<secret>))
client.get(index="abc-001",id = '--index001')

This code works correctly and gives me objectAPIresponse.

But making small change to the code as such:

client.get(index="abc-*",id = '--index001')

gives me an error:

AuthorizationException: AuthorizationException(403, 'security_exception', 'action [indices:data/read/get] is unauthorized for API key id [<id>] of user [<user>], this action is granted by the index privileges [read,all]')

I face same issue when using client.exists(index,id)

I need to assume that I don't know the full index name and need to know if index "abc-*" does exists in deployment. Even somehow if we can ignore the id and just know if the index is existing, that would be helpful.

Hi @Akhil_Sharma,

Thanks for reaching out here. How are you storing your secrets? Are you running the code inside of a Jupyter Notebook?

Lately with Elastic Cloud I've been authenticating using code similar to this:

def connect_to_elastic():
    elastic_cloud_id = os.getenv("ELASTIC_CLOUD_ID")
    elastic_api_key = os.getenv("ELASTIC_API_KEY")
    return Elasticsearch(cloud_id=elastic_cloud_id, api_key=elastic_api_key)

Best,

Jess

Hello @jessgarson ,

I am running the code through VScode but same can be run on Jupyter notebook.
The authentication works correctly for me. I was able to even get correct search result when I do not use wildcard '*' character.

But I was facing issue when I used wildcard in index name.

Anyways, The problem is solved for me using:

client.search(index = index,body = query)

I can use wildcard character in index name and query multiple index at once.

Thankyou for follow up.

1 Like

Glad to hear the problem has been solved. Let us know if you need any further help.