是否可以查询2个不同标签在指定列表中具有值的记录?
matches_list = ["4000000031265595", "4000000031265596", "4000000030004305", "4000000029975772"]
query = {
"query": {
"bool": {
"must": [
{"match": {"id_1": matches_list}},
{"match": {"id_2": matches_list}}
]
}
}
}
以上回报:
elasticsearch.exceptions.TransportError: TransportError(500, u'illegal_state_exception', u"Can't get text on a START_ARRAY at 1:57")
更新
使用大型列表时出错:
File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 128, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 122, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, u'search_phase_execution_exception', u'failed to create query: {\n "bool" : {\n "must" : [\n {\n "terms" : {\n "id_1" : my list in here ],\n "boost" : 1.0\n }\n }\n ],\n "disable_coord" : false,\n "adjust_pure_negative" : true,\n "boost" : 1.0\n }\n}')
答案 0 :(得分:1)
match
查询不适用于数组但使用单个字符串输入。请改用terms
:
query = {
"query": {
"bool": {
"must": [
{"terms": {"id_1": matches_list}},
{"terms": {"id_2": matches_list}}
]
}
}
}
答案 1 :(得分:0)
试试这个:
{
"query": {
"bool": {
"must": [
{"bool": {
"should": [
{"match": {"id_1": "4000000031265595"}},
{"match": {"id_1": "4000000031265596"}}
]
}},
{"bool": {
"should": [
{"match": {"id_2": "4000000031265595"}},
{"match": {"id_2": "4000000031265596"}}
]
}}
]
}
}
}