【发布时间】:2018-01-04 15:02:07
【问题描述】:
使用 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 中正确解析?
【问题讨论】:
标签: python curl elasticsearch