Convert Kibana query (create index pattern) to Python

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

PUT /.kibana/_doc/index-pattern:tempindex
{
  "type": "index-pattern",
  "index-pattern": {
    "title": "tempindex",
    "timeFieldName": "sendTime"
  }
}
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

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

What am I doing wrong?

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
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
Then you would send this request to your local Kibana.

Best,
Matthias

1 Like

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.

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.

1 Like

I had a mini question here.

The doc 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.

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

1 Like

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