# 'Create Index Pattern' via python3 / API

**URL:** https://forum.opensearch.org/t/create-index-pattern-via-python3-api/16455
**Category:** OpenSearch
**Created:** [October 26, 2023, 5:33pm UTC](https://forum.opensearch.org/t/create-index-pattern-via-python3-api/16455 "2023-10-26T17:33:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![DanG](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@DanG](https://forum.opensearch.org/u/DanG)
#### Post date: [October 26, 2023, 5:33pm UTC](https://forum.opensearch.org/t/create-index-pattern-via-python3-api/16455/1 "2023-10-26T17:33:04Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):

OpenSearch Dashboards v2.5.0

**Describe the issue** :

Using python3 and the API, have successfully ingested data, created an index and bulk loaded the data.

I have a dashboard that I manually set up by going to Stack Management → Index Patterns → Create Index Pattern; and creating an index pattern with the data I uploaded; then I can make dashboards / visualizations.

Is there a way via the API to do this part “Stack Management → Index Patterns → Create Index Pattern”?

My hope is that since I have a manual dashboard, when I upload new data to the same index, if I can re-create or update the index pattern, the dashboard will just update to reflect the new data that has been added.

Not certain if this is possible; appreciate any ideas.

Thanks!

Dan.

**Configuration** :

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

### Author: ![gaobinlong](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gaobinlong/32/5242_2.png) [@gaobinlong](https://forum.opensearch.org/u/gaobinlong)
#### Post date: [October 27, 2023, 3:41am UTC](https://forum.opensearch.org/t/create-index-pattern-via-python3-api/16455/2 "2023-10-27T03:41:59Z")

</div>

You can call the saved object API of OpenSearch-Dashboards, note the request url should be OSD’s endpoint, not OpenSearch’s, like this:

```auto
$ curl -X POST localhost:5601/api/index_patterns/index-pattern/my-pattern -H 'osd-xsrf: true' -H 'Content-Type: application/json' -d '
{
  "attributes": {
    "title": "my-pattern-*"
  }
}'

```

---

<div class="post-metadata">

### Author: ![DanG](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@DanG](https://forum.opensearch.org/u/DanG)
#### Post date: [March 12, 2024, 1:58am UTC](https://forum.opensearch.org/t/create-index-pattern-via-python3-api/16455/3 "2024-03-12T01:58:50Z")

</div>

Thank you for your suggestion; my email notifications were ending up in spam and I missed this one (plus our OpenSearch work stalled, we are back on it now 🙂 ).

When I attempt in dev tools, I am getting :

_NOTE : wr\_0135\_20240226110442 is the exact name of the source that has been successfully ingested_

POST /api/index\_patterns/index-pattern/wr\_0135\_20240226110442 -H ‘osd-xsrf: true’ -H ‘Content-Type: application/json’ -d ’  
{  
“attributes”: {  
“title”: “wr\_0135\_20240226110442”  
}  
}’

{  
“error”: “no handler found for uri [/api/index\_patterns/index-pattern/wr\_0135\_20240226110442] and method [POST]”  
}

* * *

Some additional information, after our last server update, the workflow I am trying to reproduce with the API is :

Dashboard management → Index Pattern → Create Index Pattern

where we specify the ingested data (index pattern name) and the time field in order to produce the Index Pattern.

Searching through the API documentation, I cannot find a reference that allows us to do this. It is the last piece blocking our full utilization of Opensearch.

Appreciate your help!

---- More Information ----

I saw a reply you posted regarding Kibana API, I tried :

curl -k -u ‘username:pswd’ -X POST https://\<server\_hn\>:9200/api/saved\_objects/index-pattern/wr\_0135\_20240226110442 -H ‘osd-xsrf: true’ -H ‘Content-Type: application/json’ -d ‘{“attributes”:{“title”: “wr\_0135\_20240226110442”}}’

Response :

{“error”:“no handler found for uri [/api/saved\_objects/index-pattern/wr\_0135\_20240226110442] and method [POST]”}-bash-4.2$

---

<div class="post-metadata">

### Author: ![gaobinlong](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/gaobinlong/32/5242_2.png) [@gaobinlong](https://forum.opensearch.org/u/gaobinlong)
#### Post date: [March 12, 2024, 2:33am UTC](https://forum.opensearch.org/t/create-index-pattern-via-python3-api/16455/4 "2024-03-12T02:33:13Z")

</div>

The API is not in OpenSearch, but in OpenSearch-Dashboards, so you need to access the endpoint of OpenSearch-Dashboards whose port is 5601:

```auto
curl POST https://<the domain of OpenSearch-Dashboards>:5601/api/saved_objects/index-pattern/wr_0135_20240226110442

```
