2017-07-28 7 views
1

作業カールを使用してからのpythonの構文は、次のリクエストが動作します。私は今のpython経由elasticsearch使用しようとしているElasticsearch - カール例

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

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で正しく解析するには何が必要ですか?

答えて

2

これを試してください:result = es.search(index= "dumperino",body=qu)