【发布时间】:2016-07-03 09:12:36
【问题描述】:
我需要执行两个查询,得到这两个的并集,然后对合并的结果进行排序和限制。
查询只是术语查询:
{
"query": {
"term": { "a.field": "A" }
},
"sort": [
{ "another.field": {"order": "desc"}}
],
"size": 25
}
我查看了 dis_max 查询,但无法单独对查询进行排序和限制。
等效的 SQL 是:
select * from (
(select * from my_table where a_field="A" order by another_field desc limit 25)
union
(select * from my_table where a_field="B" order by another_field desc limit 25)
) t order by yet_another_field limit 25;
此查询的另一部分在弹性搜索中比在关系数据库中要快得多。这就是为什么我希望看到这在弹性搜索中起作用。有可能吗?
编辑
不能选择同时使用“A”和“B”值的术语查询。这是因为当按“another.field”排序时,没有“B”文档可能会进入结果集以便稍后按“yet_another_field”排序。
【问题讨论】:
标签: elasticsearch