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
end


In Controller:-
@users =  User.search(params[:skills],
params[:developer],params[:country]).records

Comments

Popular Posts

How to pass hash in Postman

nginx: unrecognized service

Reading Excel Sheets using "Roo" gem in ruby on rails

Bootstrap Select Picker append add new item if search not exist

Add CORS to Nginx on AWS Elastic Beanstalk

Enable gzip compression on Elastic Beanstalk with nginx

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Get video duration by URL in Ruby on Rails

site-enables nginx setting in ruby in rails