Convert Kibana query (create index pattern) to Python request

丶灬走出姿态 提交于 2020-08-10 03:37:31

问题


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).


回答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.



来源:https://stackoverflow.com/questions/63146474/convert-kibana-query-create-index-pattern-to-python-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!