在阅读轮胎文档时,我的印象是你应该使用其中之一mapping或to_indexed_json方法,因为(我的理解是......)mapping用来喂养to_indexed_json.
问题是,我找到了一些使用它们的教程.为什么?
基本上,我的应用程序现在正在使用to_indexed_json但我无法弄清楚如何设置某些属性的提升值(因此我开始查看映射的原因),我想知道是否使用两者会产生一些冲突.
我正在使用Tire和ActiveRecord为elasticsearch索引数据集.我有一个Artist模型,has_many:images.如何索引返回特定图像的Artist模型的方法?或者参考相关模型的方法?我想要的艺术家结果将包括与艺术家相关的主要图像的路径(原始图像和缩略图).
我试过这个映射:
mapping do
indexes :id, :index => :not_analyzed
indexes :name
indexes :url
indexes :primary_image_original
indexes :primary_image_thumbnail
end
Run Code Online (Sandbox Code Playgroud)
引用这些Artist方法:
def primary_image_original
return images.where(:priority => 'primary').first.original
end
def primary_image_thumbnail
return images.where(:priority => 'primary').first.thumbnail_150
end
Run Code Online (Sandbox Code Playgroud)
这只是忽略了索引方法.基于其他答案,如Elasticsearch,Tire和嵌套查询/与ActiveRecord的关联,我试过这个:
mapping do
indexes :id, :index => :not_analyzed
indexes :name
indexes :url
indexes :images do
indexes :original
indexes :thumbnail_150
indexes :priority
end
end
def to_indexed_json
to_json(include: { images: { only: [:original, :thumbnail_150, :priority] } } )
end
Run Code Online (Sandbox Code Playgroud)
但这也不会归还我所追求的.我花了几个小时谷歌搜索和阅读elasticsearch和Tire文档,并没有找到这个模式的工作示例.谢谢你的想法!
运行:Ruby 1.9.3p0(2011-10-30修订版33570)[x86_64-darwin11.2.0],Rails 3.2.0
我正试图通过各种协会的TIRE宝石进行弹性搜索.出于某种原因,我在TIRE导入或偶尔在视图上执行rake时不断收到以下错误/错误:
Daves-MacBook-Pro:outdoor dave$ rake environment tire:import CLASS=Gear FORCE=true
[IMPORT] Deleting index 'gears'
[IMPORT] Creating index 'gears' with mapping:
{"gear":{"properties":{}}}
[IMPORT] Starting import for the 'Gear' class
--------------------------------------------------------------------------------
101/101 | 100% rake aborted!######################################
undefined method `last_name' for nil:NilClass
Tasks: TOP => tire:import
Run Code Online (Sandbox Code Playgroud)
这是我的模型: GEAR
class Gear < ActiveRecord::Base
attr_accessible :title, :size, :price, :image_url, :sub_category_id, :user_id
belongs_to :user
belongs_to :sub_category
validates :title, presence: true
validates :size, presence: true
validates :price, presence: true
validates :sub_category_id, presence: true
validates :user_id, presence: …Run Code Online (Sandbox Code Playgroud)