繁体   English   中英

如何在 Elasticsearch Kibana 内置的 Python 脚本中成功编写和运行 SQL 查询?

[英]How to successfully write & run a SQL query in Python script which is built in Elasticsearch Kibana?

我一直在尝试在 ES Kibana 中运行的 python 脚本中实现 SQL 查询,但是当我运行它时,我遇到了错误。

以下查询在 Kibana 中工作

POST _opendistro/_sql?format=json
{
  "query": "select * from test_index where ['title_name.S'] like 'iron%' limit 10"
}

以下是我在 Python 脚本中使用的 function 的片段。

def sql(index):
    response = es.search(
        body ={
                "query":  "select * from " + index + " limit 10"
            }
        )
    return response

以下是我尝试运行脚本时遇到的错误。

在此处输入图像描述

是否有替代方法来解决或修复此问题? 任何帮助将非常感激!

假设您使用的是 elasticsearch -py Python 客户端,您似乎正在使用搜索 API ,它向索引的_search端点发出 GET 请求。 您要发送的是对_opendistro/_sql端点的 POST 请求。 You won't find an API for that in the Python client, but you can use eg the Python requests library to issue any HTTP request.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM