现在我有以下代码:
search = Tire.search ['object1_index', 'object2_index'] do |search|
search.query { string params[:q] }
end
@results = search.results
现在的结果都来自 object1,但是,如果我用相同的查询删除“object1_index”,我会得到 object2 结果。如何让我的搜索同时与两个索引交互?
编辑:
我现在有以下内容(使用我在我的模型上定义的搜索),但由于我最终将添加分页,我不确定这是否是最好的解决方法:
object1_results = Object1.search(params).results
object2_results = Object2.search(params).results
@results = object1_results + object2_results
@results.sort!(&:_score)
最佳答案
只需添加 size
参数,因为 elasticsearch 默认大小为 10,这在您的情况下必须仅限于 object1_index
搜索空间
search = Tire.search ['object1_index', 'object2_index'], size: 1000 do |search|
...
更新
对于分页,可以添加from
参数
关于ruby-on-rails - ElasticSearch/Tire 只返回一个索引的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19839502/