我有一个有选民的邮政模型 . 在弹性搜索中,我已将Post编入索引,以便我有以下示例数据: name: 'My first post', voter_ids: [1,2,3]
. 我正在尝试搜索帖子,以便我只获得给定voter_ids的结果 . 例如,如果搜索说 1,2
,我想在结果中获得 My first post
,因为它有voter_ids 1和2,但如果搜索是 1,5
,我不应该在我的结果中看到该帖子,因为选民5从未在该帖子上投票 . 以下代码返回所有指定了任何voter_ids的帖子 . 所以它就像OR-ing . 我在寻找的是和 .
@posts = Post.search(load: true) do |tire|
tire.filter :terms, :voter_ids => voter_ids
end
1 回答
创建相当于:
From reading the elasticsearch docs
terms
过滤器上有execution
参数,您可以将其设置为and
.祝好运!