https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model
やりたいこと:
こちらのgemを使って、あるモデルをelasticsearchで検索できるようにしています。
あくまで例なのですが、User
というモデルがあって
id, first_name, last_name
というカラムを持っていたとします。
ここで、カラムにない
class User ... def full_name first_name + last_name end ... end
というfull_name
もindexに加えて検索したいと思います。
試したこと:
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
https://stackoverflow.com/questions/13600086/index-the-results-of-a-method-in-elasticsearch-tire-activerecord
こちらなどを参考にして見ましたが、いまいちうまく行きません。
現象としては、kibanaで見たときに full_name
がそもそもindexに含まれていないです。
elasticsearchが初心者なので色々と理解していない部分もあるのですが、
一般的にどのようにすれば良いのか教えて頂きたいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。