[英]How to create index of an instance method in elasticsearch-rails?
我想做的事
https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model
使用这个gem,我想创建用户模型的索引,包括名为full_name
的方法的输出。 User
具有id, first_name, last_name
列。
class User
...
def full_name
first_name + last_name
end
...
end
我做了什么
module UserSearchable
extend ActiveSupport::Concern
included do
include Searchable
settings index: {
...
}
mappings do
indexes :id, type: :integer
indexes :first_name, type: text
indexes :last_name, type: text
indexes :full_name, type: text, as: 'full_name'
end
def as_indexed_json(options={})
as_json(
methods: [:full_name]
)
end
end
end
我提到了这个问题。 在ElasticSearch中对方法的结果编制索引(Tire + ActiveRecord)
但这不起作用,最终在响应中不包含full_name
索引。
我是Elasticsearch和elasticsearch-rails的新手。 我怎样才能解决这个问题?
抱歉,我只是忘了重新加载代码中的更改! 并且它不使用as: 'full_name'
在当前版本的gem中as: 'full_name'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.