Use Analyzers Properly
Analyzers decide how Elasticsearch breaks text into words.
The default is standard
, but you can use others like english
, whitespace
, or custom
.
Example:
"analyzer": "english"
helps with stemming (e.g., running → run).
If you store multilingual data, define separate fields:
"name_en": { "type": "text", "analyzer": "english" }, "name_id": { "type": "text", "analyzer": "indonesian" }
Delete Old Data Automatically with ILM
If you store logs or time-based data, don’t keep everything forever.
Use Index Lifecycle Management (ILM) to:
- Rollover to a new index after N GB or days
- Move old data to “cold” nodes
- Delete very old data automatically
Example Policy:
PUT _ilm/policy/logs_policy { "policy": { "phases": { "hot": { "actions": { "rollover": { "max_age": "7d" } } }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } }
This keeps your storage clean and your cluster fast.
Monitor Your Cluster Health
Always know if your cluster is healthy.
You can check it with:
GET _cluster/health
Statuses:
- Green: everything is fine
- Yellow: some replicas missing
- Red: primary shards missing (serious problem)
Use Kibana Monitoring or ElasticHQ plugin to watch performance.
Use Aliases for Safer Updates
Instead of changing index names in your app, use index aliases.
This makes versioning easier.
Example:
POST /_aliases { "actions": [ { "add": { "index": "users_v2", "alias": "users" } }, { "remove": { "index": "users_v1", "alias": "users" } } ] }
Your app always searches “users”, even if you change versions behind the scenes.
Cache Smartly and Tune Queries
- Use
filter
for cacheable queries. - Use
sort
onkeyword
or numeric fields (not on analyzed text). - Use
_source
filtering to return only needed fields:
"_source": ["id", "name", "price"]
This saves bandwidth and memory.
Secure Your Cluster
Never expose Elasticsearch directly to the internet.
Use:
- HTTP authentication or API keys
- Firewalls or VPC access only
- SSL/TLS for encryption
- Regular backups with snapshots
Conclusion
Elasticsearch can handle millions of records, but only if you use it the right way.
By planning your mappings, managing shards wisely, and using filters and ILM, you will have a stable, fast, and safe system.
Start small. Test queries. Watch performance.
These small habits will make you a professional Elasticsearch user faster than you think.