python - 将Kibana查询(创建索引模式)转换为Python请求

标签 python elasticsearch kibana elasticsearch-py

我正在尝试将此Kibana查询转换为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)
但这给了我
{'statusCode': 404, 'error': 'Not Found', 'message': 'Not Found'}
我究竟做错了什么?
附注:Elastic和Kibana服务器都是本地服务器(Windows 10)。

最佳答案

似乎仅更改uri就可以解决问题:

uri = "http://localhost:9200/.kibana/_doc/index-pattern:tempindex"
但是我不确定lupanoide指出的HEADERS和cuz,应该存在kbn-xsrf: true,但是无论哪种方式似乎都有效,而且结果显然是相同的(我尚未发现任何区别)。
编辑:正如doc所说:

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


所以我认为应该存在。

关于python - 将Kibana查询(创建索引模式)转换为Python请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63146474/

相关文章:

elasticsearch - camel-elasticsearch 2.11.x不能远程工作吗?

python - elasticsearch/Kibana 列表字段为 "?",虽然它在索引中是 "text",为什么?

elasticsearch - Kibana 4 Metric 可视化显示最新值

python - Python中均匀分布的随机字符串

python - 在PCA之前对标准化感到困惑

python - 基于 Pandas 中唯一数字的两个 csv 文件之间的日期差异

elasticsearch - 在ElasticSearch中进行聚合查询时如何忽略尾随空格

python - 获取如下所示的 25x2 数组(带有坐标的排序列表)

elasticsearch - 如何有条件地在ElasticSearch中添加多个条件?

nginx - Kubernetes 中带有 nginx 入口 Controller 的 Kibana