【发布时间】:2012-07-15 12:59:52
【问题描述】:
我正在通过轮胎宝石使用弹性搜索。
给定这个结构来索引我的资源模型
mapping do
indexes :_id
indexes :version, analyzer: 'snowball', boost: 100
indexes :resource_files do
indexes :_id
indexes :name, analyzer: 'snowball', boost: 100
indexes :resource_file_category do
indexes :_id
indexes :name, analyzer: 'snowball', boost: 100
end
end
end
如何检索具有给定 resource_file_category id 的 resource_files 的所有资源?
我查看了弹性搜索文档,我认为可以使用 has child 过滤器 http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html
我试过这种方法
filter :has_child, :type => 'resource_files', :query => {:filter => {:has_child => {:type => 'resource_file_category', :query => {:filter => {:term => {'_id' => params[:resource_file_category_id]}}}}}}
但我不确定是否可以/有效地制作“嵌套的 has_child 过滤器”,或者是否有更好/更简单的方法来做到这一点......欢迎任何建议;)
【问题讨论】:
-
我的建议是远离父/子,只是将类别非规范化到记录中,作为 ID/名称/等数组。一旦你开始工作,你就可以继续使用嵌套或父/子功能。
标签: ruby-on-rails elasticsearch tire