
Elasticsearch is a powerful search and analytics engine, widely used for indexing and querying large datasets. If you’ve already installed Elasticsearch, this guide will walk you through running an example to demonstrate its core functionalities. Let's dive in!
Running the Elasticsearch Example
1. Start Elasticsearch
The first step is to get Elasticsearch up and running.
Open a terminal in Ubuntu.
By default, Elasticsearch runs on http://localhost:9200. To verify it:
Open the URL in a browser, or
Run this command in the terminal:
curl -X GET 'http://localhost:9200'

You should see a JSON response with Elasticsearch details, confirming that the server is active.
2. Create an Index
An index is like a database in Elasticsearch—it serves as a container for your data. Let’s create one for storing book data.
Open another terminal and execute the following command:
curl -X PUT 'http://localhost:9200/books'

3. Add Data to the Index
Now, let’s populate the books index with some sample data.
Add Document 1:
curl -X PUT 'http://localhost:9200/books/_doc/1' -H 'Content-Type: application/json' -d '{
"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"publisher": "J.B. Lippincott & Co.",
"year": 1960
}'

Add Document 2:
curl -X PUT 'http://localhost:9200/books/_doc/2' -H 'Content-Type: application/json' -d '{
"title": "1984",
"author": "George Orwell",
"publisher": "Secker & Warburg",
"year": 1949
}'

Add Document 3:
curl -X PUT 'http://localhost:9200/books/_doc/3' -H 'Content-Type: application/json' -d '{
"title": "Pride and Prejudice",
"author": "Jane Austen",
"publisher": "T. Egerton",
"year": 1813
}'

Each of these commands inserts a book record as a document in the books index.
4. Search for Data
One of Elasticsearch’s primary strengths is its ability to quickly search data. Here’s how you can search for books by a specific author.
Search for books authored by Harper Lee:
curl -X GET 'http://localhost:9200/books/_search' -H 'Content-Type: application/json' -d '{
"query": {
"match": {
"author": "Harper Lee"
}
}
}'

The output will be a JSON response containing all documents where the author is "Harper Lee."
5. Filter Data
Filtering allows you to retrieve documents based on specific criteria. Let’s filter books published after 1900.
Execute this command to retrieve books published in or after the year 1900:
curl -X GET 'http://localhost:9200/books/_search' -H 'Content-Type: application/json' -d '{
"query": {
"range": {
"year": {
"gte": 1900
}
}
}
}'

Every curl command above returns a JSON response. These responses contain details like the document ID, matched results, and metadata about the retrieved documents. By analyzing the responses, you can confirm that Elasticsearch is functioning as expected.
Struggling with Data Searches? Let Elasticsearch Help!
At Codersarts, we specialize in Elasticsearch Development Services to help you harness the full potential of this powerful search and analytics engine. Whether you’re building scalable search solutions, optimizing query performance, or managing real-time data indexing, our expert developers are here to assist.
Contact us today to hire skilled Elasticsearch developers and transform how you search, analyze, and manage your data!

Keywords: Elasticsearch Development Services, Elasticsearch Development Services, Elasticsearch Workflow Automation, Elasticsearch Query Optimization Services, Elasticsearch Integration Services, Data Pipeline Development with Elasticsearch, Elasticsearch Index Customization, Building ETL Pipelines with Elasticsearch, Real-time Data Processing with Elasticsearch, Data Engineering with Elasticsearch, Hire Elasticsearch Developer, Elasticsearch Project Help, Elasticsearch Freelance Developer
Comments