I have a model named Product. I provided a full text search to search products and producing a type-ahead on the client side using AngularJS. The search query was a normal like query as :
select * from products where name like = %abc% and company_id = 123;
However as my records in the table grew, the search time using the above method increased, so I decided to implement elastic search. I'm using two gems gem 'elasticsearch-model'and gem 'elasticsearch-rails'
.
How can I index the Product Model. I tried using this Product._elasticsearch_.create_index!
command in the rails console it gave the following error :
2.4.0 :006 > Product._elasticsearch_.create_index!
ArgumentError: products does not exist to be imported into. Use create_index! or the :force option to create it.
Below are my implementations :
The Product Model
require 'elasticsearch/model'
class Product < ApplicationRecord
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
belongs_to :company
belongs_to :category
belongs_to :gst
belongs_to :user
has_many :invoice_details
self.per_page = 100
Product.import
end
Product.import
line in theproduct.rb
file? And you should create two questions, becuse you are asking two things in this question. – HillerElasticsearch::Model
module – Hiller