How to Use Elasticsearch: Best Guide to Index, Search & Analyze Data
Jul 09, 2026 7 Min Read 27 Views
(Last Updated)
Table of contents
- TL;DR Summary
- What is Elasticsearch?
- Why Use Elasticsearch for Indexing, Search, and Data Analysis?
- How to use Elasticsearch: Simple Workflow
- How to use Elasticsearch: Set up
- How to use Elasticsearch to Create an Index
- How to use Elasticsearch to Add Documents to an Elasticsearch Index
- How to use Elasticsearch to search Data in Elasticsearch
- How to Use Elasticsearch for Basic Queries
- Match Query
- Term Query
- Range Query
- Bool Query
- How to Filter, Sort, and Limit Search Results
- How to use Elasticsearch to Analyze Text
- Mapping vs Analyzer in Elasticsearch
- Real-World Example: Product Search in an E-commerce App
- Common Elasticsearch Errors Beginners Face
- Connection Refused
- Index Not Found
- Mapping Conflict
- Bad Request
- No Results Found
- Common Mistakes to Avoid When Using Elasticsearch
- Treating Elasticsearch Like a Relational Database
- Ignoring Mappings
- Using Term Query on Text Fields
- Indexing Unnecessary Data
- Best Practices for Using Elasticsearch
- Build Full Stack Skills With HCL GUVI
- Final Thoughts
- FAQs
- What is Elasticsearch used for?
- How do I create an index in Elasticsearch?
- What is a document in Elasticsearch?
- What is Elasticsearch indexing?
- How do I search data in Elasticsearch?
- What is Query DSL in Elasticsearch?
- What is an analyzer in Elasticsearch?
- What is the difference between mapping and analyzer?
- Is Elasticsearch a database?
- Is Elasticsearch good for beginners?
TL;DR Summary
Elasticsearch is a distributed search and analytics engine used to index, search, and analyze data quickly. To use Elasticsearch, you create an index, add JSON documents, define mappings if needed, run search queries using Query DSL, filter or sort results, and use analyzers for full-text search. It is commonly used for website search, product search, log analytics, application monitoring, and real-time data analysis. Beginners can start with simple product data to understand how indexing, searching, and analysis work together.
If you want to learn how to use Elasticsearch, the best way is to understand three things first: indexing, searching, and analyzing data.
Elasticsearch helps you store JSON data, search it quickly, and analyze large volumes of information in near real time.
It is widely used in product search, website search, log analytics, monitoring dashboards, and search-heavy applications.
In this guide, we will explain Elasticsearch in a beginner-friendly way with simple examples and practical steps.
What is Elasticsearch?
Elasticsearch is a search and analytics engine used to store, search, and analyze data quickly.
It stores data as JSON documents inside indexes and allows you to search that data using queries. For example, an e-commerce app can use Elasticsearch to help users search for products by name, brand, category, price range, or description.
In simple words, Elasticsearch is useful when your application needs fast search, full-text search, filtering, sorting, or real-time data analysis. This guide will help you to learn how to use Elasticsearch.
Why Use Elasticsearch for Indexing, Search, and Data Analysis?
Elasticsearch is useful because normal databases are not always designed for fast full-text search.
A relational database is good for structured data and transactions. But if you want to search text, match keywords, rank results, filter by price, sort by rating, or analyze logs quickly, Elasticsearch is a better fit.
You can use Elasticsearch for:
- Product search in e-commerce apps
- Website search
- Log analytics
- Application monitoring
- Security analytics
- Real-time dashboards
- Document search
- Customer support search
- Data exploration
For example, a shopping app can use Elasticsearch to let users search products by name, brand, category, description, price range, and rating.
How to use Elasticsearch: Simple Workflow
Elasticsearch may sound complex, but the basic workflow is simple.
Here is how it works:
- You create an index.
- You add JSON documents to the index.
- Elasticsearch analyzes and stores the data.
- You run search queries.
- Elasticsearch returns matching results.
- You filter, sort, or analyze the results.
Think of an index like a folder, and documents like files inside that folder.
For example, if you are building product search, you can create an index called products and add documents for each product.
Each product document may include product name, category, price, brand, description, rating, and availability.
If you want to understand indexing at a deeper level, learning basic indexing techniques can help you see how search systems organize data for faster retrieval.
If you are already familiar with programming concepts, understanding indexing in Python can make it easier to relate how data positions and lookup patterns work at a basic level.
Here’s a quick visual overview of how to use Elasticsearch that takes data from indexing to searching and analysis.
Elasticsearch is fast because it uses an inverted index. Instead of checking every document one by one, it maps each searchable word or token to the documents where that word appears. This is one of the main reasons Elasticsearch can return full-text search results quickly, even when the dataset is large.
How to use Elasticsearch: Set up
There are different ways to set up Elasticsearch.
Beginners can use:
- Elastic Cloud
- Docker
- Local installation
- A managed Elasticsearch service
The exact setup steps may vary based on your version and installation method.
For learning purposes, many beginners prefer Docker or Elastic Cloud because they are easier to start with.
Once Elasticsearch is running, it usually exposes an HTTP API. You can send requests to Elasticsearch using tools like:
- Kibana Dev Tools
- Postman
- cURL
- Application code
For this beginner guide, we will use simple JSON examples that can be tested in Kibana Dev Tools or similar API tools.
How to use Elasticsearch to Create an Index
An index is where Elasticsearch stores related documents.
For example, if you want to store product data, you can create an index called products.
Use this request:
PUT /products
This creates an index named products.
You can also create an index with mappings. Mappings help Elasticsearch understand how each field should be treated.
Example:
PUT /products
{
“mappings”: {
“properties”: {
“name”: { “type”: “text” },
“category”: { “type”: “keyword” },
“brand”: { “type”: “keyword” },
“price”: { “type”: “float” },
“rating”: { “type”: “float” },
“available”: { “type”: “boolean” },
“description”: { “type”: “text” }
}
}
}
Here, name and description are text fields because users may search words inside them.
Fields like category and brand are keywords because they are usually used for exact filtering.
How to use Elasticsearch to Add Documents to an Elasticsearch Index
A document is a JSON object stored inside an index.
Let us add a product document to the products index.
POST /products/_doc/1
{
“name”: “Wireless Bluetooth Headphones”,
“category”: “Electronics”,
“brand”: “SoundMax”,
“price”: 2499,
“rating”: 4.4,
“available”: true,
“description”: “Comfortable wireless headphones with deep bass and long battery life”
}
This adds one product document with ID 1.
You can add another product like this:
POST /products/_doc/2
{
“name”: “Gaming Laptop”,
“category”: “Computers”,
“brand”: “TechPro”,
“price”: 65000,
“rating”: 4.6,
“available”: true,
“description”: “High performance laptop for gaming, coding, and design work”
}
Each document becomes searchable after it is indexed.
Elasticsearch is called a near real-time search engine because newly indexed documents may not appear in search results instantly. By default, Elasticsearch refreshes active indices about every second, which makes new data searchable very quickly for most real-world use cases.
How to use Elasticsearch to search Data in Elasticsearch
To search data in Elasticsearch, you use the _search API.
Example:
GET /products/_search
{
“query”: {
“match_all”: {}
}
}
This returns all documents from the products index.
If you want to search for products related to headphones, use a match query.
GET /products/_search
{
“query”: {
“match”: {
“description”: “wireless headphones”
}
}
}
This searches the description field for relevant terms.
Elasticsearch does not only look for exact matches. It analyzes the text and tries to return relevant results based on the query. This is how to use Elasticsearch.
How to Use Elasticsearch for Basic Queries
Elasticsearch uses Query DSL, which is a JSON-based way to write search queries.
Here are a few beginner-friendly queries.
1. Match Query
A match query is used for full-text search.
GET /products/_search
{
“query”: {
“match”: {
“name”: “gaming laptop”
}
}
}
This searches for products related to “gaming laptop.”
2. Term Query
A term query is used for exact matches.
GET /products/_search
{
“query”: {
“term”: {
“category”: “Electronics”
}
}
}
Use term queries mainly on keyword fields like category, brand, or status.
3. Range Query
A range query is used to search within a numeric or date range.
GET /products/_search
{
“query”: {
“range”: {
“price”: {
“gte”: 1000,
“lte”: 5000
}
}
}
}
This returns products priced between 1000 and 5000.
4. Bool Query
A bool query combines multiple conditions.
GET /products/_search
{
“query”: {
“bool”: {
“must”: [
{ “match”: { “description”: “wireless” } }
],
“filter”: [
{ “term”: { “available”: true } },
{ “range”: { “price”: { “lte”: 5000 } } }
]
}
}
}
This searches for wireless products that are available and priced below 5000.
How to Filter, Sort, and Limit Search Results
Searching is useful, but real applications also need filters and sorting.
For example, users may want to search headphones, filter only available products, sort by rating, and show only the top results.
Example:
GET /products/_search
{
“query”: {
“bool”: {
“must”: [
{ “match”: { “description”: “headphones” } }
],
“filter”: [
{ “term”: { “available”: true } }
]
}
},
“sort”: [
{ “rating”: { “order”: “desc” } }
],
“size”: 5
}
Here:
- must is used for the search condition.
- filter is used for exact filtering.
- sort arranges results by rating.
- size limits the number of results.
This is similar to what happens when you search on shopping websites.
How to use Elasticsearch to Analyze Text
Text analysis is one of the most important parts of Elasticsearch.
When you index text, Elasticsearch can break it into smaller searchable terms. This process is called analysis.
For example, the text:
“Wireless Bluetooth Headphones”
may be broken into terms like:
- wireless
- bluetooth
- headphones
This helps Elasticsearch match user searches even when the query is not exactly the same as the stored text.
Text analysis usually includes:
- Tokenization
- Lowercasing
- Removing unnecessary characters
- Applying analyzers
- Creating searchable terms
This is why Elasticsearch is powerful for full-text search.
Mapping vs Analyzer in Elasticsearch
Beginners often confuse mapping and analyzer.
Mapping defines how fields are stored and searched.
Analyzer defines how text is broken into searchable terms.
| Concept | Meaning | Example |
| Mapping | Defines field type | price is float, category is keyword |
| Analyzer | Processes text for search | Breaks “Wireless Headphones” into searchable terms |
| Keyword field | Used for exact match | Brand, category, status |
| Text field | Used for full-text search | Product name, description, article content |
For example, product descriptions should usually be stored as text because users search words inside them.
But categories should usually be stored as keywords because users filter by exact category names.
Real-World Example: Product Search in an E-commerce App
Imagine an e-commerce app that sells electronics, clothes, books, and home products.
Users should be able to search for products like:
- wireless headphones
- gaming laptop
- cotton shirt
- running shoes
They may also want to filter by category, price, brand, rating, and availability.
Elasticsearch can help by storing product documents in an index and making them searchable through queries.
For example, when a user searches “budget wireless headphones,” Elasticsearch can search product names and descriptions, filter available items, sort by rating, and return the most relevant products.
This makes search faster, more flexible, and more useful for users.
Common Elasticsearch Errors Beginners Face
Beginners may face a few common Elasticsearch errors while learning.
1. Connection Refused
This usually means Elasticsearch is not running or the URL is incorrect.
Check whether the Elasticsearch service is active and whether you are using the correct host and port.
2. Index Not Found
This happens when you search an index that does not exist.
Create the index first or check the spelling of the index name.
3. Mapping Conflict
This happens when the same field gets different data types.
For example, if price is first stored as text and later stored as a number, Elasticsearch may show a mapping issue.
4. Bad Request
This usually happens when the JSON query format is incorrect.
Check brackets, commas, field names, and query structure.
5. No Results Found
This may happen because the query does not match the analyzed text or because filters are too strict.
Try a simpler query first and then add filters one by one.
Common Mistakes to Avoid When Using Elasticsearch
Elasticsearch is powerful, but beginners often make a few common mistakes while indexing and searching data.
1. Treating Elasticsearch Like a Relational Database
Elasticsearch is not a replacement for MySQL or PostgreSQL. It is mainly used for search and analytics, so use it along with a primary database when needed.
2. Ignoring Mappings
If mappings are not planned properly, Elasticsearch may guess field types automatically. This can create issues later, especially with fields like price, date, category, or status.
3. Using Term Query on Text Fields
A term query is used for exact matches, while a match query is better for full-text search. Beginners should use matches for searchable text fields like product names or descriptions.
4. Indexing Unnecessary Data
Do not index every field if it is not needed for search or analysis. Indexing too much unnecessary data can affect storage, performance, and query speed.
Best Practices for Using Elasticsearch
Follow these best practices when using Elasticsearch:
- Use clear index names like products, logs, or articles.
- Define mappings for important fields.
- Use text fields for full-text search.
- Use keyword fields for exact filters.
- Use filters for structured conditions like category or availability.
- Use match queries for search terms.
- Keep documents simple and well-structured.
- Test queries with real sample data.
- Avoid indexing fields that are never searched.
- Monitor performance as data grows.
- Use security settings before production use.
Good Elasticsearch usage is not only about writing queries. It is about designing data in a way that makes search useful.
Build Full Stack Skills With HCL GUVI
Learning Elasticsearch helps you understand how modern applications index, search, and analyze large volumes of data. But to use it confidently, you also need strong foundations in backend development, APIs, databases, JSON, and real-world application workflows.
Explore HCL GUVI’s Full Stack Development Course to build practical skills through hands-on projects, guided learning, and job-focused training.
Final Thoughts
Learning how to use Elasticsearch becomes easier when you understand the basic workflow: create an index, add documents, run search queries, filter results, and analyze text.
Elasticsearch is useful for applications that need fast search, full-text matching, log analysis, and real-time data exploration.
Start with a simple product search example and practise basic queries before moving into advanced features.
Once you understand indexes, documents, mappings, analyzers, and Query DSL, Elasticsearch becomes a powerful tool for building search-driven applications.
FAQs
1. What is Elasticsearch used for?
Elasticsearch is used for full-text search, product search, website search, log analytics, application monitoring, security analytics, and real-time data analysis.
2. How do I create an index in Elasticsearch?
You can create an index using a PUT request like PUT /products. You can also define mappings while creating the index.
3. What is a document in Elasticsearch?
A document is a JSON object stored inside an Elasticsearch index. For example, one product record can be stored as one document.
4. What is Elasticsearch indexing?
Elasticsearch indexing is the process of storing and preparing data so that it can be searched quickly.
5. How do I search data in Elasticsearch?
You can search data using the _search API and Query DSL. For example, a match query can search text fields for relevant results.
6. What is Query DSL in Elasticsearch?
Query DSL is the JSON-based query language used by Elasticsearch to search, filter, sort, and analyze data.
7. What is an analyzer in Elasticsearch?
An analyzer processes text before indexing or searching. It can break text into tokens, lowercase terms, and prepare words for full-text search.
8. What is the difference between mapping and analyzer?
Mapping defines the structure and type of fields, while an analyzer defines how text fields are processed for search.
9. Is Elasticsearch a database?
Elasticsearch stores data, but it is not a traditional relational database. It is mainly used as a search and analytics engine.
10. Is Elasticsearch good for beginners?
Yes, beginners can learn Elasticsearch by starting with simple concepts like index, document, mapping, analyzer, and basic search queries.



Did you enjoy this article?