1

I'm trying to convert this Kibana query to Python:

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

This is what I have so far:

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?

P.S: Both Elastic and Kibana servers are local (Windows 10).

Xadra
  • 21
  • 9

1 Answers1

1

Seems that just changing the uri does the trick:

uri = "http://localhost:9200/.kibana/_doc/index-pattern:tempindex"

But I'm not sure about the HEADERS, cuz as lupanoide pointed out, kbn-xsrf: true should be present, but either way it seems to be working and apparently the results are the same (I haven't spotted a difference yet).

Edit: As the doc says:

kbn-xsrf: true

By default, you must use kbn-xsrf for all API calls, except in the following scenarios:

The API endpoint uses the GET or HEAD operations
The path is whitelisted using the server.xsrf.whitelist setting
XSRF protections are disabled using the server.xsrf.disableProtection setting

So I think it should be present.

Xadra
  • 21
  • 9
  • that header should be present for the other API, the kibana one. However elastic says that write directly to the .kibana index makes the data corrupted and permanently breaks future Kibana versions https://www.elastic.co/guide/en/kibana/master/dashboard-api.html Good luck!! – Lupanoide Jul 29 '20 at 12:31
  • That's why I said it "seems" to be working. Thank you. – Xadra Jul 29 '20 at 12:38