我能够在弹性搜索中查询索引。而且,现在我想将数据缩小到某些特定字段。但是,我不断收到错误。
这是我的查询:
es = Elasticsearch(hosts="myhost", "port":0000)
search_body={
"bool":{
"filter":[
{"exists": {"field": "customer_name"}},
{"match_phrase": {"city": "chicago"}},
]
}
}
results = es.search(index="some_index", query=search_body)
到目前为止,我很容易得到结果。但是,由于返回的字段太多,我想在将其转换为数据框之前只检索特定字段。我可以将其转换为数据框,然后进行过滤,但这不是最佳的。
我尝试添加_source
和field
方法:
search_body={
"bool":{
"filter":[
{"exists": {"field": "customer_name"}},
{"match_phrase": {"city": "chicago"}},
]
},
"_source":{"fields": {"includes":["customer_name", "city", "company", "company_address"] }}
}
和其他变体,例如,
"fields": {"includes":["customer_name", "city", "company", "company_address"] }
# or
"_source":{"includes":["customer_name", "city", "company", "company_address"] }
# and several others.
我不断收到错误:
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', '[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]')
我跟着:
- https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html
- https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering
- 几个stackoverflow答案
- 甚至尝试过命名查询
我在这里想念什么?