我有以下型号。
class Author
include Tire::Model::Search
include Tire::Model::Callbacks
has_many :books
has_many :tags #(eg: 'german', 'philosopher')
end
class Book
belongs_to :author
belongs_to :book_type #(eg: 'paperback', 'hardcover')
has_many :tags #(eg: 'crime', 'drama')
end
我需要帮助理解和编写以下搜索查询,
Find all authors who are tagged as 'german' AND 'philosopher' have written at least 1 book each of book_type 'paperback' AND 'hardcover' where each such book is tagged as 'crime' AND 'drama' Find all authors who are tagged as 'german' AND 'philosopher' have written at least 1 book of any book_type where that book is tagged as 'crime' AND 'drama'
我添加了一个带有样本种子数据@ https://github.com/rahul/nested_tire_query_problem
的迷你导轨项目更新
我试图在include books中为作者写一个映射作为'嵌套'类型。但是to_indexed_json方法会覆盖映射中的定义,并在作者中创建非嵌套书籍。
后端:MySQL(我使用to_indexed_json将文档提供给elasticsearch)
感谢任何帮助!