[英]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.