将Kibana查询(创建索引模式)转换为Python请求 [英] Convert Kibana query (create index pattern) to Python request

查看:128
本文介绍了将Kibana查询(创建索引模式)转换为Python请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此Kibana查询转换为Python:

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)

但这给了我

{'statusCode': 404, 'error': 'Not Found', 'message': 'Not Found'}

我在做什么错了?

PS:Elastic和Kibana服务器都是本地服务器(Windows 10).

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

推荐答案

似乎只需更改uri就能解决问题:

Seems that just changing the uri does the trick:

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

但是我不确定HEADERS,因为 lupanoide 指出,kbn-xsrf: true应该是目前,但无论哪种方法似乎都有效,并且结果显然是相同的(我还没有发现任何区别).

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

作为文档说:

kbn-xsrf: true

默认情况下,您必须对所有API调用使用kbn-xsrf,但在 以下情况:

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

API端点使用GETHEAD操作
使用 server.xsrf.whitelist 设置将路径列入白名单
使用server.xsrf.disableProtection设置

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.

这篇关于将Kibana查询(创建索引模式)转换为Python请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆