elasticsearch with fields
In Model:-
require 'elasticsearch/model'
class User < ActiveRecord::Base
include Elasticsearch::Model
after_save :reindex_users
before_destroy :reindex_users
settings index: { number_of_shards: 2, number_of_replicas: 0 } do
mapping do
indexes :skills
indexes :country
indexes :developer
end
end
def reindex_users
if self.changed?
self.__elasticsearch__.index_ document
# self.user.__elasticsearch__. index_document
#self.jobbers.__elasticsearch_ _.index_document
end
end
def self.search(skills,developer, country)
__elasticsearch__.search(
{
query: { query_string: {
query: "skills:\"#{skills}\" OR developer:\"#{developer}\" OR country:\"#{country}\""
}}
}
)
end
endrequire 'elasticsearch/model'
class User < ActiveRecord::Base
include Elasticsearch::Model
after_save :reindex_users
before_destroy :reindex_users
settings index: { number_of_shards: 2, number_of_replicas: 0 } do
mapping do
indexes :skills
indexes :country
indexes :developer
end
end
def reindex_users
if self.changed?
self.__elasticsearch__.index_
# self.user.__elasticsearch__.
#self.jobbers.__elasticsearch_
end
end
def self.search(skills,developer,
__elasticsearch__.search(
{
query: { query_string: {
query: "skills:\"#{skills}\" OR developer:\"#{developer}\" OR country:\"#{country}\""
}}
}
)
end
Comments
Post a Comment