python - 如何在 Elasticsearch Kibana 中内置的 Python 脚本中成功编写和运行 SQL 查询?
问题描述
我一直在尝试在 ES Kibana 中运行的 python 脚本中实现 SQL 查询,但是当我运行它时,我遇到了错误。
以下查询在 Kibana 中工作
POST _opendistro/_sql?format=json
{
"query": "select * from test_index where ['title_name.S'] like 'iron%' limit 10"
}
以下是我在 Python 脚本中使用的函数片段。
def sql(index):
response = es.search(
body ={
"query": "select * from " + index + " limit 10"
}
)
return response
以下是我尝试运行脚本时遇到的错误。
是否有替代方法来解决或修复此问题?任何帮助将非常感激!
解决方案
assuming you're using the elasticsearch-py Python client, it seems you're using the search API, which issues GET requests to the _search
endpoint of an index. What you want to send instead is a POST request to the _opendistro/_sql
endpoint. You won't find an API for that in the Python client, but you can use e.g. the Python requests
library to issue any HTTP request.
推荐阅读
- java - 维基百科中的opensearch结果为java中的jsonobject
- for-loop - Golang 一行 for 循环
- python - 多类继承
- redis - Redis 映像目前是否可以在 Windows 上与 Docker 一起使用?
- installation - Pdf2Html 安装
- android - Android MMS Content Provider 不存储事务 ID
- c++ - 对没有数组的输出数字进行排序
- java - 如何确定通过brew服务运行的Java elasticsearch
- javascript - 将 json 数据从 javascript 发送到 python 时发生内部服务器错误
- android - 如何将 firebase firestore 用于我的桌面应用程序?