What I want to do
https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model
Using this gem, I wanna create indexes of User model, including output of method named full_name
. User
has columns of id, first_name, last_name
.
class User
...
def full_name
first_name + last_name
end
...
end
What I did
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
I referred to this question. Index the results of a method in ElasticSearch (Tire + ActiveRecord)
But this doesn't work, ending up with not containing full_name
index in the response.
I'm new to elasticsearch and elasticsearch-rails. How can I fix this?
include UserSearchable
at the top of class definition. – lacostenycodermethods: [:country_ja, :full_name],
take a look at github.com/elastic/elasticsearch-rails/tree/master/… – lacostenycoder