简体   繁体   中英

Elasticsearch - python syntax from working curl example

Using curl, the following request works:

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.

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'}}]}}}]")

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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