# Convert Kibana query (create index pattern) to Python

**URL:** https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991
**Category:** Kibana
**Created:** [July 29, 2020, 4:24am UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991 "2020-07-29T04:24:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![momora9809](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@momora9809](https://discuss.elastic.co/u/momora9809)
#### Post date: [July 29, 2020, 4:24am UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/1 "2020-07-29T04:24:53Z")

</div>

Hi,  
I'm trying to convert this query to python:

```auto
PUT /.kibana/_doc/index-pattern:tempindex
{
  "type": "index-pattern",
  "index-pattern": {
    "title": "tempindex",
    "timeFieldName": "sendTime"
  }
}

```

```auto
HEADERS = {
    'Content-Type': 'application/json'
}

uri = "http://localhost:5601/_doc/index-pattern:tempindex"

query = json.dumps({
  "type": "index-pattern",
  "index-pattern": {
    "title": "tempindex",
    "timeFieldName": "sendTime"
  }
})

r = requests.put(uri,headers=HEADERS, data=query).json()
print(r)

```

But it gives me

```auto
{'statusCode': 404, 'error': 'Not Found', 'message': 'Not Found'}

```

What am I doing wrong?

---

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [July 29, 2020, 2:42pm UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/2 "2020-07-29T14:42:32Z")

</div>

Hi  
Kibana is sending this request to Elasticsearch, so you might be more successful sending this request to  
[http://localhost:9200/.kibana/\_doc/index-pattern:tempindex](http://localhost:9200/.kibana/_doc/index-pattern:tempindex)  
given that Elasticsearch is running local and using this port.

Or you could use our saved object API  
[https://www.elastic.co/guide/en/kibana/current/saved-objects-api-create.html](https://www.elastic.co/guide/en/kibana/current/saved-objects-api-create.html)  
Then you would send this request to your local Kibana.

Best,  
Matthias

---

<div class="post-metadata">

### Author: ![momora9809](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@momora9809](https://discuss.elastic.co/u/momora9809)
#### Post date: [July 29, 2020, 2:46pm UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/3 "2020-07-29T14:46:51Z")

</div>

Would u plz explain in what situation I need to use that API?  
Like when I have an index pattern somewhere and want to use it somewhere else?  
Thanks.

---

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [July 29, 2020, 2:55pm UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/4 "2020-07-29T14:55:43Z")

</div>

it's useful when you don't have direct access to ES. so you'd need you 1 endpoint, that's Kibana. you don't need to know about .kibana or \_doc (type). you could export or backup you index pattern and insert it into another Kibana. however, also the API way is experimental.

---

<div class="post-metadata">

### Author: ![momora9809](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@momora9809](https://discuss.elastic.co/u/momora9809)
#### Post date: [July 29, 2020, 3:35pm UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/5 "2020-07-29T15:35:48Z")

</div>

I had a mini question here.

The [doc](https://www.elastic.co/guide/en/kibana/master/dashboard-api.html) says

> Do not write documents directly to the `.kibana` index. When you write directly to the `.kibana` index, the data becomes corrupted and permanently breaks future Kibana versions.

Should I be worried? I tested it but everything seemed fine.

---

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [July 29, 2020, 5:28pm UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/6 "2020-07-29T17:28:41Z")

</div>

We don’t officially support it and if you do it wrong you can break stuff .. and fix it by deleting it again. If it works for you it’s fine, but you have to be aware that there might be changes in the futur

---

<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: [August 26, 2020, 5:30pm UTC](https://discuss.elastic.co/t/convert-kibana-query-create-index-pattern-to-python/242991/7 "2020-08-26T17:30:55Z")

</div>

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