Spring boot -Elastic Search – Setup and CRUD

Step 1: Understanding Elasticsearch

  • What is Elasticsearch?
    Elasticsearch is a distributed, RESTful search and analytics engine capable of handling large volumes of data in near real-time. It’s commonly used for search functionality, log analysis, and data visualization.
  • Core Concepts:
  • Index: Like a database in RDBMS. It stores related documents.
  • Document: A single unit of data, stored in JSON format.
  • Shard & Replica: A shard is a subset of an index; replicas are backups of shards.

Step 2: Setup Elasticsearch

1. Install Elasticsearch

  • Download the latest version from Elasticsearch Downloads.
  • Unzip the downloaded package.
  • Run Elasticsearch:
    • Linux/Mac: ./bin/elasticsearch
    • Windows: bin\elasticsearch.bat
    • config folder -> elasticsearch.yml -> set security to false
    • default username – elastic
    • default password – shows in logs
      Note – Navigate to the Elasticsearch bin directory.
      Run this command: elasticsearch-reset-password -u elastic
      Follow the prompts to set a new password.
  • Verify it’s running: Open http://localhost:9200 in a browser or use curl:
    bash curl -X GET "localhost:9200/"

Note – To allow traffic on port 9200 for Elasticsearch in Windows, you need to create a firewall rule. Here’s how to do it:
Steps to Allow Inbound Traffic on Port 9200
Open Windows Defender Firewall:
Press Windows + R to open the Run dialog.
Type control and press Enter to open the Control Panel.
Navigate to System and Security > Windows Defender Firewall.
Advanced Settings:
On the left side, click on Advanced settings. This opens the Windows Defender Firewall with Advanced Security window.
Create a New Inbound Rule:
In the left pane, select Inbound Rules.
In the right pane, click on New Rule….
Select Rule Type:
Choose Port and click Next.
Specify Port and Protocol:
Select TCP.
In the Specific local ports field, enter 9200.
Click Next.
Allow the Connection:
Choose Allow the connection and click Next.
Profile Selection:
Select when this rule applies (Domain, Private, Public). It’s usually safe to select all three if you are on a private network.
Click Next.
Name the Rule:
Give your rule a name (e.g., “Elasticsearch Port 9200”).
Optionally, add a description.
Click Finish.
Verify the Rule is Active:
Ensure that your new rule appears in the list of inbound rules and is enabled (it should be checked).

Github Project link – https://github.com/kuldeep101990/Spring-Boot-Elastic-Search

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *