简体   繁体   English

Elasticsearch-工作curl示例中的python语法

[英]Elasticsearch - python syntax from working curl example

Using curl, the following request works: 使用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"   }}
      ]
    }
  }
}
'

I'm now trying to use elasticsearch via python. 我现在正尝试通过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)

Error: 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'}}]}}}]") 错误: 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'}}]}}}]")

I've used this format successfully before, albeit with a simpler string query before. 我之前已经成功使用了这种格式,尽管之前使用了更简单的字符串查询。

What do I need to change in the JSON query for elasticsearch to parse this correctly in Python? 我需要在JSON查询中更改什么以使Elasticsearch在Python中正确解析此内容?

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

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

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