By: Category: Ruby on Rails,Web Development Technologies: Ruby on Rails
What is Elasticsearch?
Elasticsearch is a powerful full-text search engine based on Apache Lucene. Elastic search is a search engine based on Apache Lucene — and an information retrieval software library. It allows us to store, search and analyze big volumes of data in real-time.
Full-text search engine: A search engine examines all of the words in every stored document as it tries to match search criteria.
Apache Lucene: It is a search engine library written entirely in java.
Following are the steps
1) rails new elastic_search_app
2) cd elastic_search_app
3) bundle
4) rails db:create db:migrate db:seed
5) rails assets:precompile
6) Performed the CRUD for Post Model.
7) rails db:migrate
8) set routes
9) rails s
10) In the gem file add the below line of code
11) Add the below code in the post.rd file
12) Install Elasticsearch
Steps of Installation of elastic search:
Configure elastic search:
Securing elastic search:
Testing elastic search:
13) We are going to create a class method in the post model that will take the search query as an argument but it will fetch only published posts. Add the following method in the app/models/post.rb file:
14) Add the search action in the post controller
15) Update the routes like below
16) Update the code of index.mhtl.erb under app/views/posts and add the following code.
17) rails s