问题
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
orHEAD
operations
The path is whitelisted using the server.xsrf.whitelist setting
XSRF protections are disabled using theserver.xsrf.disableProtection
setting
So I think it should be present.
来源:https://stackoverflow.com/questions/63146474/convert-kibana-query-create-index-pattern-to-python-request