Elasticsearch is powerful, but it can also be confusing for new users.
Many people make mistakes that slow down performance, waste memory, or even break the cluster.
This article explains best practices for beginners — simple rules that help you build a stable and fast Elasticsearch setup.
Plan Before You Index
Many problems come from rushing to insert data without a plan.
Before indexing, always decide:
- What kind of data do you store? (text, number, date, keyword)
- How will people search it? (full text, exact match, range, filter)
Tip:
Create a mapping first. Do not rely on automatic mapping.
For example, if you store a user’s name and age:
PUT /users { "mappings": { "properties": { "name": { "type": "text" }, "age": { "type": "integer" } } } }
This saves time later and keeps your searches accurate.
Use the Right Field Type
Choosing the wrong type can break searches or use too much memory.
Field Type | Use For | Example |
---|---|---|
text | Full-text search | “organic coffee beans” |
keyword | Exact match / filter | “SKU12345” |
integer , float | Numbers | price, rating |
date | Time data | “2025-10-05” |
Common mistake:
Using text
for IDs or codes.
That makes filtering slow, use keyword
instead.
Don’t Create Too Many Indices or Shards
Each index and shard uses memory.
Too many small shards can make your cluster slow, even if data is small.
Tip:
- Keep shard size around 10–50 GB for logs or documents.
- Combine similar data into one index with a field like
type
orcategory
. - Start with 1–3 shards per index, and use replicas for safety.
Example:
Bad:
index per user → user_001, user_002, user_003
Good:
one index → users (with field user_id)
Use Filters for Fast Exact Searches
Full-text queries like match
calculate scores.
If you only need to filter, use filter
inside a bool
query — it’s faster because filters are cached.
Example:
GET /products/_search { "query": { "bool": { "must": { "match": { "category": "coffee" } }, "filter": { "term": { "in_stock": true } } } } }
This query searches coffee products and filters only those in stock.