我在Elasticsearch 1.x中有这样的查询:
{"filter": {"and": {"filters": [{"exists": {"field": "body"}}, {"query": {"term": {"accept": "true"}}},
{"exists": {"field": "thumbnail"}}, {"query": {"terms": {
"content": ["577f6ca06dd5340a97e89923"]}}}, {"range": {
"date": {"lt": "2018-01-05T04:07:48.901933", "gte": "1963-04-04T04:07:48.901933"}}},
{"query": {"terms": {
"agency": ["577ff7176dd5340a97e899b7"]}}}, {"query": {"terms": {
"subject": ["578c6c7f6dd5345f3db18e7b"]}}}, {"query": {
"terms": {"geographic": ["577f78fe6dd5340a97e89948"]}}}]}},
"fields": ["_id", "link", "title"], "from": 0,
"sort": {"date": {"order": "desc"}}, "size": 30}
它适用于1.x版本但在5.x版本中出现错误:
elasticsearch.exceptions.RequestError: TransportError(400, u'parsing_exception', u'Unknown key for a START_OBJECT in [filter].')
我该怎么办?
答案 0 :(得分:1)
尝试此查询,它应该有效:
{
"query": {
"bool": {
"filter": [
{
"exists": {
"field": "body"
}
},
{
"term": {
"accept": "true"
}
},
{
"exists": {
"field": "thumbnail"
}
},
{
"terms": {
"content": [
"577f6ca06dd5340a97e89923"
]
}
},
{
"range": {
"date": {
"lt": "2018-01-05T04:07:48.901933",
"gte": "1963-04-04T04:07:48.901933"
}
}
},
{
"terms": {
"agency": [
"577ff7176dd5340a97e899b7"
]
}
},
{
"terms": {
"subject": [
"578c6c7f6dd5345f3db18e7b"
]
}
},
{
"terms": {
"geographic": [
"577f78fe6dd5340a97e89948"
]
}
}
]
}
},
"_source": [
"_id",
"link",
"title"
],
"from": 0,
"sort": {
"date": {
"order": "desc"
}
},
"size": 30
}