【问题标题】:Elasticsearch - python syntax from working curl exampleElasticsearch - 来自工作 curl 示例的 python 语法
【发布时间】:2018-01-04 15:02:07
【问题描述】:

使用 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"Failed to parse query [{'query': {'bool': {'should': [{'match': {'id_1': '4000000029898186'}}, {'match': {'id_2': '4000000029898188'}}]}}}]")

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

我需要在 JSON 查询中进行哪些更改才能让 elasticsearch 在 Python 中正确解析?

【问题讨论】:

    标签: python curl elasticsearch


    【解决方案1】:

    请试试这个:result = es.search(index= "dumperino",body=qu)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多