← All insightsCheat Sheet

Elasticsearch cheat sheet: the complete command reference

CodeWizard Engineering · 7 August 2025 · 3 min read · Beginner

This is a complete, hands-on Elasticsearch cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.

Elasticsearch is a distributed search and analytics engine built on Lucene, widely used for log analytics (the ELK/Elastic stack), full-text search and, increasingly, vector search.

Why you reach for it

  • Powerful full-text search and aggregations
  • Mature log analytics with Kibana
  • Scales horizontally with sharding and replicas

Installation

bash
docker run -p 9200:9200 -e discovery.type=single-node \
  -e xpack.security.enabled=false docker.elastic.co/elasticsearch/elasticsearch:8.15.0

Configuration reference

Create an index with an explicit mapping.

bash
curl -X PUT localhost:9200/logs -H 'Content-Type: application/json' -d '{
  "mappings": { "properties": {
    "@timestamp": { "type": "date" },
    "level": { "type": "keyword" },
    "message": { "type": "text" }
  } }
}'

Core commands you use daily

bash
curl -X POST localhost:9200/logs/_search -H 'Content-Type: application/json' -d '{
  "query": { "match": { "message": "timeout" } }
}'

_cat APIs (operations)

bash
curl -s localhost:9200/_cat/health?v
curl -s localhost:9200/_cat/indices?v
curl -s localhost:9200/_cat/nodes?v
curl -s localhost:9200/_cat/shards?v

Index, search, ILM

bash
curl -X POST localhost:9200/logs/_doc -H 'Content-Type: application/json' -d '{"level":"error","message":"timeout"}'
curl -X POST localhost:9200/logs/_search -H 'Content-Type: application/json' -d '{"query":{"match":{"message":"timeout"}}}'
curl -X PUT localhost:9200/_ilm/policy/logs -H 'Content-Type: application/json' -d '{...}'

Use it in CI/CD

Provide Elasticsearch as a CI service.

yaml
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.15.0
    env: { discovery.type: single-node, xpack.security.enabled: 'false' }
    ports: ['9200:9200']

Best-practice checklist

  • Define explicit mappings; disable dynamic where possible
  • Use Index Lifecycle Management for retention/rollover
  • Size shards deliberately (tens of GB each)

Common pitfalls to avoid

  • Unbounded mapping explosion from dynamic fields
  • Too many small shards hurting performance
  • No ILM, so indices grow without retention

Security quick wins

  • Enable security (TLS + auth); never expose 9200 publicly
  • Use role-based access and API keys

Works well with

  • Grafana Loki - Prometheus-style log aggregation that indexes labels, not full text - cheap and Grafana-native.
  • Grafana - The open dashboarding layer for metrics, logs and traces, with alerting across many data sources.
  • Vector Databases - Similarity search over embeddings - the retrieval backbone of RAG and semantic search (Pinecone, Weaviate, Qdrant).
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.

Want senior help putting Elasticsearch to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult