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

**URL:** <https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 26, 2024, 2:02pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185 "2024-03-26T14:02:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akhil\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhil_sharma/32/132986_2.png) [@Akhil\_Sharma](https://discuss.elastic.co/u/Akhil_Sharma)\
**Post date:** [March 26, 2024, 2:02pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185/1 "2024-03-26T14:02:31Z")

</div>

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

```auto
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:

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

```

gives me an error:

```auto
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.

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [March 26, 2024, 5:03pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185/2 "2024-03-26T17:03:42Z")

</div>

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:

```python
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

---

<div class="post-metadata">

**Author:** ![Akhil\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhil_sharma/32/132986_2.png) [@Akhil\_Sharma](https://discuss.elastic.co/u/Akhil_Sharma)\
**Post date:** [March 29, 2024, 6:54am UTC](https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185/3 "2024-03-29T06:54:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [March 29, 2024, 2:46pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185/4 "2024-03-29T14:46:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2024, 2:47pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-unable-to-get-data-when-included-in-index-name/356185/5 "2024-04-26T14:47:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
