Searchkick による Elasticsearch の使用。
私のドキュメントは次のようになります。
{
"_id" : ObjectId("54f8672f258f83ac4e7783e5"),
"n" : "Figth Club",
"dst" : "video",
"detail" : {
est: "El club de la lucha",
ent: "Figth club",
hut: "Harcosok klubja"
}
}
私のアイテムモデル:
class Item
include Mongoid::Document
searchkick
def search_data
{
n: n,
est: detail.est,
ent: detail.ent,
hut: detail.hut,
}
end
end
検索クエリは次のようになります。
Item.search(query, fields: [:n, :est, :ent, :hut], limit: 10).to_a
クエリが見つかったフィールドを知りたいです。たとえば、それが見つかったフィールドquery="El club de la lucha"を知りたい場合。detail.estそれは可能ですか?