我想用 UNION 和 limit 进行查询。
我可以解释一下 mysql 上的查询。
(SELECT
*
FROM table
WHERE type='text'
LIMIT 3
)
UNION
(SELECT
*
FROM table
WHERE type='word'
LIMIT 3
)
我在 Elasticsearch 上尝试过
{
"query":{
"dis_max":{
"queries":[
{
"from":0,
"size":3,
"query":{
"match":{
"type":"text"
}
}
},
{
"from":0,
"size":3,
"query":{
"match":{
"type":"word"
}
}
}
]
}
}
}
{%22query%22:{%22dis_max%22:{%22queries%22:[{%22query%22:{%22match%22:{%22type%22:%22test%22}}}]}}}
然后,错误发生了。
{
"error" : {
"root_cause" : [ {
"type" : "query_parsing_exception",
"reason" : "[_na] query malformed, no field after start_object",
"index" : "test",
"line" : 1,
"col" : 34
} ],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [ {
"shard" : 0,
"index" : "test",
"node" : "U6yIqY-pS526Vz8QTi6d0Q",
"reason" : {
"type" : "query_parsing_exception",
"reason" : "[_na] query malformed, no field after start_object",
"index" : "test",
"line" : 1,
"col" : 34
}
} ]
},
"status" : 400
}
当我仅使用匹配查询时,它起作用了。但对于尺寸来说,它不起作用。
我该如何解决?