[英]Elasticsearch - python syntax from working curl example
使用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中正確解析此內容?
請嘗試以下操作: result = es.search(index= "dumperino",body=qu)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.