python - 将 Kibana 查询(创建索引模式)转换为 Python 请求
问题描述
我正在尝试将此 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'}
我究竟做错了什么?
PS:Elastic 和 Kibana 服务器都是本地的(Windows 10)。
解决方案
似乎只是改变uri
了诀窍:
uri = "http://localhost:9200/.kibana/_doc/index-pattern:tempindex"
但我不确定HEADERS
, 因为lupanoide指出的kbn-xsrf: true
应该存在,但无论哪种方式它似乎都在工作,显然结果是相同的(我还没有发现差异)。
编辑:正如文档所说:
kbn-xsrf: true
默认情况下,您必须
kbn-xsrf
对所有 API 调用使用,但以下情况除外:API 端点使用
GET
orHEAD
操作使用server.xsrf.whitelist设置
将路径列入白名单XSRF 保护使用设置 禁用server.xsrf.disableProtection
所以我认为它应该存在。
推荐阅读
- javascript - 更改 Material-ui 中扩展父扩展面板上的扩展面板箭头颜色
- swift - 在 swift 5 中观察屏幕录制
- docker - 如何在 CRI-O 上运行的 Minikube 中加载本地 Docker 映像?
- kubernetes - 如何在 Grafana helm chart 中配置自定义 LDAP?
- java - WebTestClient 变异过滤器 java.lang.IllegalStateException:没有“WebTestClient-Request-Id”标头
- node.js - 如何使用多个 Nodejs 服务器通信
- javascript - Rails:Webpacker 4.2 在 /app/public/packs/manifest.json heroku 中找不到应用程序
- docker - yaml.parser.ParserError - 为什么它不起作用?
- laravel - 在 Laravel 中制作 Guzzle HTTP POST 请求
- javascript - 为所有请求添加动态标头