Ruby on rails 4 使用chewy将rails应用程序连接到elasticsearch
我正在使用chewy gem将ES绑定到我的rails应用程序。我是chewy的新手,所以当我尝试为模型的字段编制索引时,我面临一个问题。该字段是数据库中的文本字段,我在模型中将其序列化为哈希。散列是动态的,在表单中可能包含0到n个元素。字段名为items如有任何帮助,将不胜感激Ruby on rails 4 使用chewy将rails应用程序连接到elasticsearch,ruby-on-rails-4,
elasticsearch,chewy-gem,Ruby On Rails 4,
elasticsearch,Chewy Gem,我正在使用chewy gem将ES绑定到我的rails应用程序。我是chewy的新手,所以当我尝试为模型的字段编制索引时,我面临一个问题。该字段是数据库中的文本字段,我在模型中将其序列化为哈希。散列是动态的,在表单中可能包含0到n个元素。字段名为items如有任何帮助,将不胜感激 {"0"=>{"property"=>"value","property"=>"value"},"1"=>{"property"=>"value","property"=>"valu
{"0"=>{"property"=>"value","property"=>"value"},"1"=>{"property"=>"value","property"=>"value"}.......}
当我定义_类型时,如何在索引类中索引此类字段
这是我的索引器
require 'typhoeus/adapters/faraday'
class ModelNameIndex < Chewy::Index
define_type ModelName do
field :user_id, type: 'integer'
field :enduser_id, type: 'integer'
field :items, type: 'object'
field :created, type: 'date', include_in_all: false,
value: ->{ created_at }
end
end
需要“台风/适配器/法拉第”
类ModelNameIndex{created_at}
结束
结束
我的模型
class ModelName < ActiveRecord::Base
update_index('IndexName#name') { self }
belongs_to :user
serialize :items, Hash
end
classmodelname
上述代码工作正常
require 'typhoeus/adapters/faraday'
class ModelNameIndex < Chewy::Index
define_type ModelName do
field :user_id, type: 'integer'
field :enduser_id, type: 'integer'
field :items, type: 'object'
field :created, type: 'date', include_in_all: false,
value: ->{ created_at }
end
end
需要“台风/适配器/法拉第”
类ModelNameIndex{created_at}
结束
结束
如果有人出现解析错误,请确保ElasticSearch没有您之前定义的任何键,否则它将抛出错误。谢谢您的提问和回答。我有类似的情况,我的疑问是如何搜索和过滤字段“项目”。例如:-获取ModelName中的所有行,这些属性值大于items对象中键“1”的“特定值”。