1

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?

1 Answer 1

2

Please try this: result = es.search(index= "dumperino",body=qu)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.