python - Elasticsearch - 来自工作 curl 示例的 python 语法

标签 python curl elasticsearch

使用curl,以下请求有效:

curl -XGET 'localhost:9200/dumperino/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "should": [
        { "match": { "id_1":  "4000000029898186" }},
        { "match": { "id_2":  "4000000029898188"   }}
      ]
    }
  }
}
'

我现在尝试通过 python 使用elasticsearch。

from elasticsearch import helpers
es = elasticsearch.Elasticsearch()
qu={
  "query": {
    "bool": {
      "should": [
        { "match": { "id_1":  "4000000029898186" }},
        { "match": { "id_2": "4000000029898188"   }}
      ]
    }
  }
}
result = es.search(index= "dumperino",q=qu)

错误: elasticsearch.exceptions.RequestError: TransportError(400, u'search_phase_execution_exception', u"无法解析查询 [{'query': {'bool': {'should': [{'match': {'id_1'' : '4000000029898186'}}, {'match': {'id_2': '4000000029898188'}}]}}}]")

我之前曾成功使用过这种格式,尽管之前使用过更简单的字符串查询。

我需要在 Elasticsearch 的 JSON 查询中更改什么才能在 Python 中正确解析它?

最佳答案

请尝试以下操作:result = es.search(index= "dumperino",body=qu)

关于python - Elasticsearch - 来自工作 curl 示例的 python 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45375239/

相关文章:

使用curl和json-c从C调用json web服务

elasticsearch - 使用从父聚合获取的参数的子聚合脚本

elasticsearch - ElasticSearch上的版本冲突

python - 禁用 QTreeWidget 中父行的选择

python - 在分组后将值滚动粘贴到字符串

python - 为什么我在 Python 的线程中得到 TypeError

search - 实现搜索 : Identifying known keywords

python - 将新的永久列添加到数据框python

node.js - PUT 的 Node JS 请求 promise

php - 使用 cURL 获取 HTTP header 并保存到变量