TechEarl

Elasticsearch Cheat Sheet

Practitioner reference for Elasticsearch 9.x: index and document operations, Query DSL, aggregations, vector / kNN search, ESQL, cluster management, a zero-downtime reindex runbook with aliases, version compatibility notes, and the gotchas that bite first-time operators.

Ishan KarunaratnePublished ⏱️ 28 min readUpdated
Share thisCopied
Elasticsearch 9.x reference: REST endpoints, Query DSL, aggregations, kNN, ESQL, cluster commands, and a zero-downtime reindex with aliases in curl and Kibana.

An Elasticsearch cheat sheet is a single-page reference for the commands and Query DSL you reach for daily: index and document operations, searches and aggregations, vector / kNN search, ESQL, and cluster management, against Elasticsearch 9.x. It also carries the full runbook for a zero-downtime reindex with aliases, in both curl and Kibana Dev Tools form.

Quick reference

Elasticsearch 9.x Quick Reference

REST endpoints, Query DSL fragments, aggregations, and admin commands for Elasticsearch 9.x.

Core concepts

ClusterOne or more nodes sharing the same `cluster.name`, coordinating to store data and serve requests.
NodeA single Elasticsearch process. Nodes have roles: master-eligible, data, ingest, coordinating, ML, transform.
IndexA logical namespace for documents. Conceptually like a database table; physically a set of one or more shards.
DocumentA JSON object stored in an index, identified by an `_id`. Has a fixed mapping (schema) once written.
ShardA Lucene index. Primary shards hold the data; replica shards are copies for redundancy and read throughput.
MappingThe schema. Defines field types (`keyword`, `text`, `long`, `date`, `dense_vector`, etc.) and how each is indexed.
AliasA pointer to one or more indices. Use aliases for zero-downtime reindexing and to abstract away rolling indices.
Data streamA managed alias over a sequence of backing indices, optimized for append-only time-series data with ILM rollover.

Index operations

GET /_cat/indices?vList all indices with health, docs count, store size.
PUT /:indexCreate an index. Optional body: `settings`, `mappings`, `aliases`.
DELETE /:indexDelete an index. Irreversible; protect with `action.destructive_requires_name: true` in production.
POST /:index/_closeClose an index. Closed indices keep their files on disk but are not searchable.
POST /:index/_openReopen a closed index.
PUT /:index/_settingsUpdate dynamic settings (number of replicas, refresh interval). Most static settings need close + reopen.
GET /:index/_mappingInspect the mapping. Run this before troubleshooting any "why didn't my query match" issue.
PUT /:index/_mappingAdd new fields to an existing mapping. Existing fields cannot be re-typed; you must reindex.
POST /_reindexCopy documents from one index to another, optionally transforming via script. Use for mapping changes or shard re-balancing.

Document operations

POST /:index/_docIndex a document with an auto-generated ID.
PUT /:index/_doc/:idCreate or replace a document with a specific ID. Returns `result: created` or `result: updated`.
PUT /:index/_create/:idCreate only. Fails with 409 if the ID already exists. Use when you must NOT overwrite.
GET /:index/_doc/:idRetrieve a document by ID, including `_source` and metadata.
POST /:index/_update/:idPartial update. Body: `{ "doc": { ... } }` for a merge, or `{ "script": { ... } }` for scripted.
DELETE /:index/_doc/:idDelete a single document by ID.
POST /:index/_delete_by_queryDelete every document matching a query. The async version returns a task ID; poll with `/_tasks/:task_id`.
POST /_bulkSend many index/create/update/delete actions in one round trip. The NDJSON format alternates action lines and source lines.
POST /_mgetMulti-get: fetch many documents by ID in one request.

Search basics

GET /:index/_searchDefault search: returns the first 10 documents sorted by relevance score.
GET /:index/_search?q=field:valueURI query string. Convenient for ad-hoc; less expressive than the JSON DSL.
POST /:index/_search { "query": { "match_all": {} } }Match every document. Equivalent to no query, but explicit.
POST /:index/_search { "query": { "match": { "title": "engine" } } }Full-text match. Runs the query through the field's analyzer; matches if any token overlaps.
POST /:index/_search { "query": { "term": { "status.keyword": "published" } } }Exact term match on a `keyword` field. No analysis. Use for IDs, enums, exact strings.
POST /:index/_search { "query": { "range": { "price": { "gte": 10, "lt": 50 } } } }Range query. Works on numeric, date, ip fields.
POST /:index/_search { "query": { "prefix": { "name.keyword": "foo" } } }Prefix match. Expensive on text fields without a properly mapped `keyword` subfield.

Compound queries (bool)

mustAll clauses must match. Contributes to the relevance score (acts like AND for ranking).
filterAll clauses must match. Does NOT contribute to the score; cached aggressively. Use for binary filters.
shouldAt least one (`minimum_should_match`, default 0 if `must`/`filter` present, else 1) must match. Contributes to score.
must_notNo clause may match. Does NOT contribute to score. Use for exclusions.
Example`{ "bool": { "must": [{"match":{"title":"phone"}}], "filter": [{"term":{"in_stock":true}}], "must_not":[{"term":{"discontinued":true}}] } }`

Search options

sizeNumber of hits to return per page. Default 10. Maximum 10000 without `search_after`.
fromPagination offset. Combined with `size`, hard-capped at `index.max_result_window` (default 10000).
search_afterCursor-based pagination using sort values from the last hit. The only way to paginate past 10000 results.
sortSort by one or more fields. Sorting on `text` fields requires `fielddata: true` (expensive) or use a `keyword` subfield.
_sourceFilter which source fields are returned. `false` = no source. Array = include only these. Object with includes/excludes for fine control.
highlightReturns matched fragments with HTML tags around hits. Useful for snippet UIs.
explainAdds `_explanation` to each hit, breaking down the score. Use when relevance ranking is mysterious.
track_total_hits`true` for exact total counts (slower); a number for accurate up to N; `false` to skip counting entirely.

Aggregations

termsBucket per distinct value: `{ "aggs": { "by_category": { "terms": { "field": "category.keyword", "size": 10 } } } }`. Like SQL GROUP BY.
date_histogramBucket by time: `{ "aggs": { "per_day": { "date_histogram": { "field": "@timestamp", "calendar_interval": "day" } } } }`.
histogramNumeric buckets at fixed interval. Useful for price brackets, latency distributions.
rangeCustom buckets with `from`/`to` boundaries. Use when buckets are not equal-width.
filtersOne bucket per named filter. Best for ad-hoc "slice the data N ways" queries.
avg / sum / min / max / statsMetric aggs. `stats` returns all five in one pass.
cardinalityApproximate distinct count (HyperLogLog). Cheap and accurate to ~40000 values.
percentilesApproximate percentile values (T-Digest). Use for latency reports.
Sub-aggregationsAggs nest: a `terms` agg can contain an `avg` sub-agg to get "average price per category".

Vector and kNN search

dense_vector field typeMapping: `{ "type": "dense_vector", "dims": 768, "index": true, "similarity": "cosine" }`. Required to query with kNN.
knn search`{ "knn": { "field": "embedding", "query_vector": [...], "k": 10, "num_candidates": 100 } }`. Returns top-k nearest neighbors.
Hybrid searchCombine kNN with a text query via `bool` and per-clause `boost` to mix semantic + lexical relevance.
Quantization`"element_type": "byte"` stores 1 byte per dimension (4x smaller than `float`). For `float` vectors, `index_options.type` such as `int8_hnsw`, `int4_hnsw` or `bbq_hnsw` quantizes the index automatically, with a minor recall cost.
Semantic textES 8.15+ field type `semantic_text` runs embedding inference at index and query time; no client-side embeddings needed.

ESQL (8.11+)

POST /_queryRun an ESQL query. Body: `{ "query": "FROM logs | WHERE status >= 400 | STATS count() BY host" }`.
FROMSource index or alias. Comma-separated for multi-source: `FROM logs-*,metrics-*`.
WHEREFilter rows. SQL-like operators: `=`, `!=`, `>`, `<`, `LIKE`, `IN`, `IS NULL`.
STATS ... BYAggregate. `STATS count() BY host, status` is equivalent to a `terms` agg on (host, status).
EVALCompute new columns: `EVAL latency_ms = duration / 1000`.
SORT / LIMITOrder and cap results. `SORT @timestamp DESC | LIMIT 50`.
When to useESQL is preferred for ad-hoc analytics and dashboards; Query DSL is still preferred for search relevance tuning.

Cluster and admin

GET /_cluster/healthCluster status: `green` (all primaries + replicas assigned), `yellow` (replicas missing), `red` (a primary is missing).
GET /_cat/nodes?vList nodes with heap, CPU, load, role.
GET /_cat/shards?vEvery shard with state (`STARTED`, `INITIALIZING`, `RELOCATING`, `UNASSIGNED`) and reason if unassigned.
GET /_cluster/allocation/explainWhen you have unassigned shards, this tells you exactly why each one can't be placed. Single most useful debug endpoint.
PUT /_cluster/settingsUpdate cluster-wide settings. `transient` (lost on restart) vs `persistent` (survives).
POST /_cluster/rerouteManually move or allocate shards. Last-resort tool; usually `allocation/explain` shows a config issue to fix instead.
GET /_nodes/hot_threadsSnapshot of what each node's hottest threads are doing. The first stop when CPU is pinned.

Snapshots and backup

PUT /_snapshot/:repoRegister a snapshot repository (S3, GCS, Azure Blob, shared filesystem).
PUT /_snapshot/:repo/:snapshotTake a snapshot. Add `?wait_for_completion=true` for synchronous (small clusters only).
GET /_snapshot/:repo/:snapshot/_statusProgress of a running snapshot.
POST /_snapshot/:repo/:snapshot/_restoreRestore a snapshot. Specify `indices` and `rename_pattern` to restore alongside live indices.
SLMSnapshot Lifecycle Management automates snapshots on a schedule with retention. `PUT /_slm/policy/:name`.

I run Elasticsearch behind a few production search experiences and an analytics pipeline. The sections below are organized in the order you actually hit them: first connect to the cluster, then create an index and load documents, then search, then aggregate, then tune.

What this cheat sheet covers

Use this page as a reference card. Each section is a self-contained chunk: skip to Search DSL if you already have a populated index, skip to Aggregations if you need facet counts, skip to Vector / kNN search if you are wiring up semantic search, or to Reindex with zero downtime when a mapping change forces a new index. The end-of-page Common mistakes and FAQ sections answer the questions I get asked most.

What this sheet does NOT cover:

  • Elastic's commercial features (Watcher, machine learning UI, cross-cluster replication). Those need an enterprise license. The free / open AGPL+ELv2 stack covers everything below.
  • Kibana dashboards. Kibana is its own product with its own docs.
  • The legacy Transport client. It was removed in Elasticsearch 8.0. Use the REST clients (Java, Python elasticsearch, Node @elastic/elasticsearch, or raw HTTP).

Connecting to Elasticsearch

Every command in this sheet is an HTTP request. I show them in curl form because that is the universal denominator. The same calls work verbatim in Kibana Dev Tools (paste without the curl -X prefix), in httpie, or through any official client.

A local single-node 9.x cluster started fresh requires basic auth (the elastic user) and HTTPS by default. The first-time setup prints the password to the console; reset it any time with:

bash
bin/elasticsearch-reset-password -u elastic

A typical authenticated request:

bash
curl -k -u elastic:CHANGEME https://localhost:9200/_cluster/health

The -k skips self-signed cert verification. For production, use a real certificate and pass --cacert instead. Most of the URLs in the rest of this sheet are shown without the host prefix; assume https://localhost:9200 (or wherever your cluster lives).

Search DSL: a worked example

The Query DSL is more verbose than the URI query string but composable. The idiom I reach for first is a bool query with must for text relevance and filter for binary conditions:

bash
curl -k -u elastic:CHANGEME -X POST "https://localhost:9200/products/_search" \
  -H 'Content-Type: application/json' -d '{
  "size": 20,
  "query": {
    "bool": {
      "must": [
        { "match": { "name": "wireless headphones" } }
      ],
      "filter": [
        { "term":  { "in_stock": true } },
        { "range": { "price": { "lte": 200 } } }
      ]
    }
  },
  "sort": [
    "_score",
    { "rating": "desc" }
  ],
  "_source": ["name", "price", "rating", "image_url"]
}'

What each part does:

  • must runs the user query through the name field's analyzer and contributes to _score.
  • filter enforces "in stock and under $200" without touching the score; these clauses are cached.
  • sort ranks by relevance first, then by rating as a tiebreaker.
  • _source restricts the response to the four fields the UI actually renders, saving bandwidth.

Aggregations: facets and analytics

Aggregations turn search results into facet counts, time series, and summary statistics. A typical product-search facet response:

bash
curl -k -u elastic:CHANGEME -X POST "https://localhost:9200/products/_search" \
  -H 'Content-Type: application/json' -d '{
  "size": 0,
  "query": { "match": { "name": "headphones" } },
  "aggs": {
    "by_brand":     { "terms": { "field": "brand.keyword", "size": 10 } },
    "price_bucket": { "histogram": { "field": "price", "interval": 50 } },
    "stats_price":  { "stats": { "field": "price" } }
  }
}'

"size": 0 skips the hits and just returns the aggregations. That is the right pattern when you only need counts.

Aggregations can nest. To get the average price by brand:

json
"aggs": {
  "by_brand": {
    "terms": { "field": "brand.keyword", "size": 10 },
    "aggs": {
      "avg_price": { "avg": { "field": "price" } }
    }
  }
}

Elasticsearch 8.x added native vector search; 9.x stabilized it as the recommended path for semantic retrieval. Define a dense_vector field in the mapping, then run a knn query with a query vector you compute client-side (or use semantic_text to skip the client step).

Mapping:

json
{
  "mappings": {
    "properties": {
      "title":     { "type": "text" },
      "embedding": { "type": "dense_vector", "dims": 768, "index": true, "similarity": "cosine" }
    }
  }
}

Query:

json
{
  "knn": {
    "field": "embedding",
    "query_vector": [0.012, -0.041, ...],
    "k": 10,
    "num_candidates": 100
  }
}

num_candidates controls recall vs latency. A common ratio is 10× k. For hybrid search that combines lexical relevance with vector similarity, put both knn and a bool/match query into the same request:

json
{
  "query": { "match": { "title": "noise cancelling" } },
  "knn":   { "field": "embedding", "query_vector": [...], "k": 10, "num_candidates": 100, "boost": 0.7 }
}

For the broader context on how vector search fits with embeddings, document chunking, and a working app, see how to build RAG with embeddings and vector search and how to add semantic search to a MySQL app.

ESQL: the SQL-like query language

Introduced in 8.11 and refined through the 8.x and 9.x lines, ESQL gives Elasticsearch a piped query language that reads like SQL with a Unix-pipeline twist. For analytics, dashboards, and log exploration it is often easier than building the equivalent Query DSL by hand.

code
FROM logs-2026.05.*
| WHERE status >= 400 AND status < 500
| STATS count = count() BY host, status
| SORT count DESC
| LIMIT 20

When to use which:

Use caseDSLESQL
Search-relevance tuning, scoringYesNo (no relevance scoring)
Time-series analytics, log queriesPossible but verboseYes
Joins across multiple indicesNoYes (LOOKUP JOIN, tech preview in 8.18/9.0, GA in 8.19/9.1)
AggregationsYesYes (cleaner syntax)
Vector / kNN searchYesNot yet

Reindex with zero downtime using an alias

To reindex Elasticsearch without search downtime, create a replacement index, copy documents with the _reindex API, validate it, then move the application's alias in one _aliases request. Searches keep using the same alias throughout. This is how you apply a mapping change you cannot make in place (see the PUT /:index/_mapping and POST /_reindex rows in the quick reference).

An alias swap does not synchronize writes. The copy can miss later inserts, updates, and deletes. This walkthrough keeps search available while pausing Elasticsearch writes from before the copy until after cutover. That is a write maintenance window, not uninterrupted read/write availability. If your application cannot pause or durably queue writes, use the change-capture approach before following the cutover steps.

Each request has a curl version and a matching Kibana Dev Tools Console version. Run one version of each request, inspect the result, and only then continue. The REST APIs used here are documented for Elasticsearch 8.x and 9.x; this is a documentation-reviewed walkthrough, not a claim that every release and deployment combination has been execution-tested, so rehearse the exact requests against your version and a representative dataset first. Managed or Serverless deployments can restrict index settings and privileges, and OpenSearch has a separate version and security model.

The pattern: applications query a stable alias

The application uses products, an alias pointing to products_v3. Build products_v4 separately, then move products once the replacement is ready. The application keeps the same endpoint. You can explore both states in the graphic; its labels follow the settings below.

One alias. Two index generations.
ApplicationSame search endpoint
Stable aliasproducts
Current index
products_v3Serving searches
New index
products_v4Copy, catch up, validate
Searches continue through products to products_v3 while products_v4 is prepared. Resolve writes before swapping.Illustration only. These controls do not connect to Elasticsearch.

An alias must have a different name from any existing index or data stream. If your application currently addresses a physical index called products, you cannot create an alias with that name alongside it. Introduce a distinct alias, deploy the application change, and verify every reader and writer uses it before migrating. Do not delete the existing index to free the name.

When a mapping change needs a reindex

Changing an existing field's type or its index-time analyzer generally means rebuilding documents in a new index. Adding a new field is different: the mapping API supports it. A new keyword multi-field is also allowed, but old documents need rewriting with _update_by_query or reindexing to populate it. Some mapping parameters, including search_analyzer, can be updated without rebuilding the index. See Elastic's update mapping API and search analyzer documentation.

Adding a dense_vector mapping does not generate embeddings. You need an embedding process or an appropriate ingest pipeline to supply vectors. The example here uses ordinary product fields so it can focus on the migration itself.

Setup: use your own values in curl and Kibana

Try it with your own values

Set the host, current index, new index, and application alias. Both command versions and the diagram update with these values. Values are saved in this browser; do not enter credentials.

In Kibana: open Dev Tools → Console on the deployment you intend to change. Paste one request, place the cursor inside it, and click its play button or press Ctrl+Enter / Cmd+Enter. Execute each request individually. A request is the GET, PUT, POST, or DELETE line plus its entire JSON body, when present; do not execute JSON lines separately. Do not select and run the whole walkthrough. Console can submit multiple requests sequentially, but an asynchronous reindex returns before the copy finishes. Console request controls.

Kibana uses its connected Elasticsearch cluster and your Kibana permissions. The host field affects curl only; changing it here cannot switch Kibana to another cluster. Compare GET / in Console with the curl response, including cluster_uuid, before continuing. These are REST requests in Console syntax, not KQL or ES|QL queries.

In a terminal: the curl examples use Bash/zsh syntax and curl 7.76+ (--fail-with-body). Set the username once; curl will prompt for its password when each request runs. Use a migration account with the required read, write, create-index, alias-management, settings, and monitoring privileges.

bash
export ES_USER='elastic'

For a self-managed cluster with a private certificate authority, configure its trusted CA certificate before running curl:

bash
export CURL_CA_BUNDLE='/absolute/path/to/http_ca.crt'

Skip that environment variable when the endpoint already has a certificate trusted by your system. Keep certificate verification enabled. For API-key authentication, replace the --user option with your locally configured authorization header. Do not enter credentials into this page.

Check the cluster identity

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/'
Kibana · Dev Tools
GET /

Before changing anything, confirm all of these:

  • You have a recoverable snapshot or source-of-truth rebuild path, enough disk for both indices and replicas, and a tested mapping.
  • This is a regular index migration within one cluster. Data streams, remote reindexing, filtered aliases, custom routing, and lifecycle-managed indices need additional planning.
  • The source has _source enabled. Reindexing reads it; it does not copy the original mapping, settings, or templates for you. Reindex prerequisites.
  • Your replacement starts empty, receives no application writes, and does not inherit the application alias from an index template. One operator controls the migration.
  • All producers can pause or durably queue writes, including background jobs, bulk importers, deletes, and direct-to-index clients. Blocking an index alone does not queue writes.

Step 1: Check the alias and source configuration

1a. Inspect the application alias

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/_alias/products'
Kibana · Dev Tools
GET /_alias/products

Expect exactly the current index with this alias under aliases. Stop if it points somewhere else, spans multiple indices, has is_write_index: false, or carries a filter or routing options you have not accounted for. Preserve any required alias options in both forward and rollback changes; the example below assumes a plain, single-index alias.

Only if the response explicitly reports alias not found (404), create the alias. Authentication failures and connectivity errors are not missing aliases.

1b. Create the alias only if it is missing

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/_aliases' \
  --header 'Content-Type: application/json' \
  --data '{
  "actions": [
    {
      "add": {
        "index": "products_v3",
        "alias": "products",
        "is_write_index": true
      }
    }
  ]
}'
Kibana · Dev Tools
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "products_v3",
        "alias": "products",
        "is_write_index": true
      }
    }
  ]
}

Wait for acknowledged: true, then repeat 1a. If you are introducing this alias, deploy and verify the application's switch to it before continuing.

1c. Inspect the source mapping

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v3/_mapping'
Kibana · Dev Tools
GET /products_v3/_mapping

1d. Record the source settings

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v3/_settings?include_defaults=true'
Kibana · Dev Tools
GET /products_v3/_settings?include_defaults=true

Record analyzers, shard count, replica policy, refresh interval, routing, and ingest-pipeline settings. Build the replacement from an explicit, reviewed definition. Do not blindly copy generated settings such as the UUID or creation date.

Step 2: Create the new index with the required mapping

This is a small example product mapping. Replace it with the schema your actual documents require, including custom analyzers and dynamic templates. Here name.keyword supports sorting and aggregations. The shard and replica choices are examples, not sizing advice.

2a. Create the empty replacement index

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request PUT 'https://localhost:9200/products_v4' \
  --header 'Content-Type: application/json' \
  --data '{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "refresh_interval": "60s"
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "description": {
        "type": "text"
      },
      "price": {
        "type": "double"
      },
      "in_stock": {
        "type": "boolean"
      }
    }
  }
}'
Kibana · Dev Tools
PUT /products_v4
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "refresh_interval": "60s"
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "description": {
        "type": "text"
      },
      "price": {
        "type": "double"
      },
      "in_stock": {
        "type": "boolean"
      }
    }
  }
}

Wait for creation to be acknowledged. If the index already exists, inspect it and choose a fresh destination name; do not delete it to make the example work. A 60-second refresh interval can reduce refresh overhead while copying. It controls search visibility, not a disk commit. Keeping a replica avoids deliberately dropping redundancy; zero replicas is an optional performance tradeoff only when the source is recoverable and you accept rebuilding the destination after a failure. Indexing-speed guidance.

2b. Inspect the destination, including inherited aliases and settings

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v4'
Kibana · Dev Tools
GET /products_v4

2c. Refresh the destination before checking that it is empty

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/products_v4/_refresh'
Kibana · Dev Tools
POST /products_v4/_refresh

2d. Confirm zero destination documents

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v4/_count'
Kibana · Dev Tools
GET /products_v4/_count

Require count: 0, no failed shards, no application alias on the destination, and no unexpected ingest pipeline. A template can add settings or aliases even when the create request does not include them. If the new index unexpectedly received the live alias, stop and repair that routing before proceeding.

Step 3: Pause writes, refresh the source, and start reindexing

Pause producers first and drain their in-flight work. Keep new operations in a durable queue or stop accepting writes for the maintenance window. Reads may continue. Then add a write block as a guard against a forgotten producer:

3a. Block writes to the old index after pausing producers

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request PUT 'https://localhost:9200/products_v3/_block/write'
Kibana · Dev Tools
PUT /products_v3/_block/write

Wait for success for every index/shard in the response. The dedicated index-block API accounts for in-flight writes before acknowledging the block. An unexpected writer now gets an error; your application must retain or retry that operation rather than lose it.

3b. Make the last source writes visible to reindex

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/products_v3/_refresh'
Kibana · Dev Tools
POST /products_v3/_refresh

Check _shards.failed: 0. A refresh makes recent operations searchable, which matters because reindex reads through search. Leave the source write-blocked through validation and cutover.

3c. Start one asynchronous reindex task

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/_reindex?wait_for_completion=false&slices=auto&requests_per_second=500' \
  --header 'Content-Type: application/json' \
  --data '{
  "source": {
    "index": "products_v3",
    "size": 1000
  },
  "dest": {
    "index": "products_v4",
    "op_type": "create"
  }
}'
Kibana · Dev Tools
POST /_reindex?wait_for_completion=false&slices=auto&requests_per_second=500
{
  "source": {
    "index": "products_v3",
    "size": 1000
  },
  "dest": {
    "index": "products_v4",
    "op_type": "create"
  }
}

The response should contain a task such as node_id:12345. This means the task started, not that the copy finished. Save the complete value, including the node ID and colon, in the task field below. Start the task once; repeat the status request instead of resubmitting _reindex.

op_type: create refuses to overwrite existing destination documents. A conflict is a reason to stop in this empty-destination workflow. Do not add conflicts: proceed just to get past it. slices: auto can parallelize work; the parent status can advance in jumps as slices finish. The throttle is an example starting point, not a guarantee of acceptable load. Monitor query latency, heap, disk, and rejections. Reindex execution and throttling.

If the start request times out without returning an ID, inspect running reindex tasks before deciding whether to retry:

3d. Find running reindex tasks only if the start response was lost

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/_tasks?actions=*reindex&detailed=true'
Kibana · Dev Tools
GET /_tasks?actions=*reindex&detailed=true

Step 4: Check reindex progress and wait for successful completion

4a. Poll this task until it finishes

Paste the complete task ID returned by the reindex request (node ID:number) before copying this request.

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/_tasks/<task_id>'
Kibana · Dev Tools
GET /_tasks/<task_id>

Repeat 4a every 5–10 seconds, or less often for a large copy. It may take minutes or hours. Do not advance to the swap while completed is false.

When it becomes true, inspect the whole response. For this unfiltered copy into an empty, private destination, require:

  • No top-level error.
  • A response object with timed_out: false and an empty failures array.
  • version_conflicts: 0.
  • created equal to total; updated, deleted, and noops equal to zero.

completed: true means the task stopped; it does not prove success. A missing task (404), lost node, cancellation, malformed response, or document failure needs investigation. Preserve the old alias and inspect the partial destination before planning a retry. Do not assume that rerunning the request resumes safely. Task status.

Step 5: Validate documents, queries, and replica readiness

5a. Refresh the destination after the copy

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/products_v4/_refresh'
Kibana · Dev Tools
POST /products_v4/_refresh

5b. Count the frozen source

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v3/_count'
Kibana · Dev Tools
GET /products_v3/_count

5c. Count the replacement

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v4/_count'
Kibana · Dev Tools
GET /products_v4/_count

Require no failed shards and equal counts for this full, write-paused migration. A lower count is not an acceptable expected gap. Equal counts are necessary here but do not prove equal content: an update can change a document without changing the total.

Compare representative document IDs and source values, then run your application's actual queries directly against the new index. Check relevance, sorting, filters, aggregations, routing, and latency. For the example mapping, this is a basic search-and-sort smoke test:

5d. Smoke-test the replacement mapping

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v4/_search' \
  --header 'Content-Type: application/json' \
  --data '{
  "size": 5,
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "name.keyword": "asc"
    }
  ]
}'
Kibana · Dev Tools
GET /products_v4/_search
{
  "size": 5,
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "name.keyword": "asc"
    }
  ]
}

Check timed_out: false and _shards.failed: 0, then inspect the returned documents. Replace this query with your real application queries as well; one generic search cannot validate the migration.

Restore your intended production settings. The example uses one replica and a one-second refresh interval. Substitute the values you chose for this deployment rather than assuming those are universal defaults.

5e. Apply the intended production settings

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request PUT 'https://localhost:9200/products_v4/_settings' \
  --header 'Content-Type: application/json' \
  --data '{
  "index": {
    "number_of_replicas": 1,
    "refresh_interval": "1s"
  }
}'
Kibana · Dev Tools
PUT /products_v4/_settings
{
  "index": {
    "number_of_replicas": 1,
    "refresh_interval": "1s"
  }
}

5f. Wait for the destination replica to be ready

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/_cluster/health/products_v4?wait_for_status=green&timeout=60s'
Kibana · Dev Tools
GET /_cluster/health/products_v4?wait_for_status=green&timeout=60s

Require timed_out: false and the expected health state. This example needs enough eligible data nodes to allocate its replica. A single-node lab with one replica stays yellow; choose an explicit lab replica policy instead of ignoring a production allocation failure. A health wait timing out means inspect allocation and repeat the check, not proceed. Cluster health.

Step 6: Swap the alias atomically, verify, then resume writes

Repeat 1a immediately before cutover. It must still resolve only to the old index. Coordinate with other operators and automation so nobody changes it during the migration.

Run both actions together as one request. Never issue separate remove and add requests.

6a. Move the alias in one request

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/_aliases' \
  --header 'Content-Type: application/json' \
  --data '{
  "actions": [
    {
      "remove": {
        "index": "products_v3",
        "alias": "products",
        "must_exist": true
      }
    },
    {
      "add": {
        "index": "products_v4",
        "alias": "products",
        "is_write_index": true
      }
    }
  ]
}'
Kibana · Dev Tools
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "products_v3",
        "alias": "products",
        "must_exist": true
      }
    },
    {
      "add": {
        "index": "products_v4",
        "alias": "products",
        "is_write_index": true
      }
    }
  ]
}

must_exist: true makes a missing removal fail instead of allowing a partial action list. Check acknowledged: true, no reported action errors, and the resulting alias. This avoids a deliberate gap in alias routing; it does not guarantee every application request succeeds regardless of cluster health or client behavior. Alias action semantics.

6b. Verify the alias points only to the new index

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/_alias/products'
Kibana · Dev Tools
GET /_alias/products

If cutover times out or returns an ambiguous result, inspect 6b before retrying. The change may already have applied.

6c. Test search through the application alias

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products/_search' \
  --header 'Content-Type: application/json' \
  --data '{
  "size": 5,
  "query": {
    "match_all": {}
  }
}'
Kibana · Dev Tools
GET /products/_search
{
  "size": 5,
  "query": {
    "match_all": {}
  }
}

Verify hits come from the new _index, check for shard failures, and test the real application. Only then resume producers and replay queued operations through the alias in order. Wait for that queue to drain before declaring the search index current. Keep the old index write-blocked so a missed direct writer fails visibly. Monitor failed writes and search latency.

When writes must continue during reindex

A background reindex is a copy, not an ongoing replication subscription. If uninterrupted writes and up-to-date searches are required, the migration needs a separate consistency protocol:

  1. Capture a durable change-log position before the baseline copy starts. Retain inserts, updates, and delete events, including document IDs and routing.
  2. Build the replacement, then replay changes into it in order. If replay overlaps the baseline, use a tested version-ordering strategy so older copied documents cannot overwrite newer changes.
  3. Establish a cutover barrier: drain in-flight writers and apply changes through a known position before moving reads. A brief ingestion pause or a coordinated writer handoff is usually necessary. Prove there is no untracked gap.
  4. Route subsequent writes to the replacement, drain remaining events, and monitor lag. Maintain the old index too if you need a rollback that preserves post-cutover writes.

Idempotency alone does not establish ordering. A second _reindex pass or an updated_at query does not reliably catch deletes and can race with new writes. Replaying only after switching reads exposes an incomplete index until replay finishes. These are application-level design decisions; the commands above do not implement change capture.

Rollback: check for new writes before moving back

The retained old index is a fallback for search, but it stops receiving writes after cutover. Once the replacement has accepted writes, an immediate reverse swap exposes stale data. Pause producers, account for in-flight operations, reconcile post-cutover inserts, updates, and deletes into the old index, and validate that its mapping can represent them. If it cannot, fix forward or rebuild from the source of truth.

Only when the old index is current and validated, or while all writes have remained paused since before the original copy, reverse the routing:

Rollback A. Swap back only after validating the old index

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request POST 'https://localhost:9200/_aliases' \
  --header 'Content-Type: application/json' \
  --data '{
  "actions": [
    {
      "remove": {
        "index": "products_v4",
        "alias": "products",
        "must_exist": true
      }
    },
    {
      "add": {
        "index": "products_v3",
        "alias": "products",
        "is_write_index": true
      }
    }
  ]
}'
Kibana · Dev Tools
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "products_v4",
        "alias": "products",
        "must_exist": true
      }
    },
    {
      "add": {
        "index": "products_v3",
        "alias": "products",
        "is_write_index": true
      }
    }
  ]
}

Repeat the alias and application checks. The old index is still write-blocked. Before resuming producers after a successful rollback, remove that block:

Rollback B. Unblock the old index before resuming writes

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request PUT 'https://localhost:9200/products_v3/_settings' \
  --header 'Content-Type: application/json' \
  --data '{
  "index.blocks.write": false
}'
Kibana · Dev Tools
PUT /products_v3/_settings
{
  "index.blocks.write": false
}

The same unblock request applies if you abandon the migration before cutover: confirm the alias still points only to the old index, stop any unwanted copy, inspect the failure, then unblock it and resume producers. Do not leave the application unintentionally stuck in its write maintenance window.

Keep the old index until the rollback window closes

Retain it for your agreed observation period, with a snapshot or reproducible rebuild path. Check all aliases, direct clients, dashboards, background jobs, and recovery requirements before deletion. Keeping an index for a day does not by itself make rollback safe.

Cleanup A. Inspect every alias on the old index

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request GET 'https://localhost:9200/products_v3/_alias'
Kibana · Dev Tools
GET /products_v3/_alias

The next request is optional and destructive. Run it separately, after the observation period and only when the old index is no longer needed. It deletes the entire named index, not just the application's alias.

Cleanup B. Delete the retired index only after sign-off

curl · Terminal
curl --fail-with-body --silent --show-error --user "$ES_USER" \
  --request DELETE 'https://localhost:9200/products_v3'
Kibana · Dev Tools
DELETE /products_v3

Optional bash helper: copy and validate, then stop for review

es-zero-downtime-reindex.shCopy a write-blocked source into an empty destination, poll the task, and check its result and document counts. Alias cutover stays manual.Download

The helper replaces the copy-and-count portion of steps 3–5. Do not run it after already starting 3c. It requires curl 7.76+, jq, an existing empty destination with your reviewed mapping, paused producers, and a write-blocked source. Set ES_USER and your CA trust as above. It prompts once for the password and does not print it.

bash · Terminal
bash es-zero-downtime-reindex.sh --host 'https://localhost:9200' --old 'products_v3' --new 'products_v4' --alias 'products'

It stops on HTTP errors, missing task IDs, task errors, timeouts, document failures, conflicts, unexpected task counts, or mismatched document counts. It leaves settings, write blocks, aliases, and index deletion to the operator. It cannot prove document equality, query correctness, or application readiness. Continue the manual validation in 5d–5f, then review cutover in step 6. The older --yes and --rollback automation options are no longer supported.

Review the helper source
bash
#!/usr/bin/env bash
# Copy and validate only. Alias cutover is intentionally manual.
# https://techearl.com/elasticsearch-zero-downtime-reindex
# Requires Bash, curl 7.76+, jq; regular indices in one Elasticsearch cluster.
set -euo pipefail

HOST="${ES_HOST:-https://localhost:9200}"
OLD_INDEX=""
NEW_INDEX=""
ALIAS=""
TASK=""

usage() {
  cat <<'HELP'
Usage: bash es-zero-downtime-reindex.sh --old NAME --new NAME --alias NAME [--host URL]

Prepare the destination mapping, pause all producers, drain in-flight writes,
and add PUT /OLD/_block/write first. The destination must be empty and private.
This helper refreshes the source, starts one reindex, polls it, and checks counts.
It NEVER swaps aliases, changes settings, unblocks writes, or deletes indices.

Auth: ES_USER (default elastic), then a password prompt; or ES_AUTH=user:password.
TLS: set CURL_CA_BUNDLE to your private CA file if needed. Verification stays on.
--yes and --rollback are no longer supported. Review the article's manual steps.
HELP
}
fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
while [[ $# -gt 0 ]]; do
  case "$1" in
    --old|--new|--alias|--host)
      [[ $# -ge 2 && -n "$2" ]] || fail "Missing value for $1"
      case "$1" in
        --old) OLD_INDEX="$2" ;;
        --new) NEW_INDEX="$2" ;;
        --alias) ALIAS="$2" ;;
        --host) HOST="$2" ;;
      esac
      shift 2 ;;
    -h|--help) usage; exit 0 ;;
    *) usage >&2; fail "Unsupported argument: $1" ;;
  esac
done
for name in "$OLD_INDEX" "$NEW_INDEX" "$ALIAS"; do
  [[ "$name" =~ ^[a-z0-9][a-z0-9._-]*$ && ${#name} -le 255 ]] || fail "Use individual lowercase names, starting with a letter or number (no wildcards)."
done
[[ "$OLD_INDEX" != "$NEW_INDEX" && "$OLD_INDEX" != "$ALIAS" && "$NEW_INDEX" != "$ALIAS" ]] || fail "Index and alias names must all differ."
[[ "$HOST" =~ ^https?://[^/?#@[:space:]\"\']+(/[^?#@[:space:]\"\']*)?$ ]] || fail "Invalid host; do not put credentials, query strings, or fragments in the URL."
HOST="${HOST%/}"
command -v curl >/dev/null || fail "curl is required"
command -v jq >/dev/null || fail "jq is required"

AUTH="${ES_AUTH:-}"
if [[ -z "$AUTH" ]]; then
  [[ -t 0 ]] || fail "Set ES_AUTH for non-interactive use, or run in a terminal for the password prompt."
  read -r -s -p "Password for ${ES_USER:-elastic}: " password
  printf '\n'
  AUTH="${ES_USER:-elastic}:$password"
  unset password
fi
[[ "$AUTH" != *$'\n'* && "$AUTH" != *$'\r'* ]] || fail "Credentials cannot contain newlines."
# Keep credentials out of command-line arguments and output.
AUTH_CONFIG="${AUTH//\\/\\\\}"
AUTH_CONFIG="${AUTH_CONFIG//\"/\\\"}"
unset AUTH ES_AUTH
es() {
  curl --config <(printf 'user = "%s"\n' "$AUTH_CONFIG") \
    --fail-with-body --silent --show-error --connect-timeout 15 --max-time 90 \
    --header 'Content-Type: application/json' "$@"
}
json_request() {
  local response
  if ! response=$(es "$@"); then
    printf '%s\n' "$response" >&2
    fail "HTTP/transport failure. Do not retry a mutation until its cluster state is known."
  fi
  printf '%s' "$response" | jq -e 'type == "object" and (has("error") | not)' >/dev/null || fail "Invalid or error API response."
  printf '%s' "$response"
}
check_shards() {
  jq -e '._shards.failed == 0 and ._shards.successful > 0' >/dev/null || fail "Missing shard status or shard failures."
}
check_alias() {
  json_request "$HOST/_alias/$ALIAS" | jq -e --arg old "$OLD_INDEX" --arg alias "$ALIAS" '
    (keys == [$old]) and (.[$old].aliases[$alias] | type == "object" and
      (has("filter") | not) and (has("routing") | not) and
      (has("index_routing") | not) and (has("search_routing") | not) and
      (.is_write_index != false))' >/dev/null || fail "Alias must point only to the source with no filter/routing and permit writes."
}
check_source_block() {
  json_request "$HOST/$OLD_INDEX/_settings?flat_settings=true" | jq -e --arg old "$OLD_INDEX" '
    (keys == [$old]) and (.[$old].settings["index.blocks.write"] | . == "true" or . == true)' >/dev/null \
    || fail "Source must be an exact index with a write block. Pause producers, then use PUT /OLD/_block/write."
}
count_index() {
  local response
  response=$(json_request "$HOST/$1/_count")
  printf '%s' "$response" | check_shards
  printf '%s' "$response" | jq -er '.count | select(type == "number" and . >= 0)'
}
reminder() {
  local code=$?
  if [[ -n "$TASK" ]]; then
    printf '\nTask ID: %s\n' "$TASK" >&2
    if [[ $code -ne 0 ]]; then
      printf 'The task may still be running. Inspect it before starting another copy.\n' >&2
    fi
  fi
  printf 'No alias/settings/deletion changes were made by this helper. Keep producers paused until cutover, or restore the old write path deliberately.\n' >&2
}
trap reminder EXIT

printf 'Checking alias, source write block, and destination...\n'
check_alias
check_source_block
json_request "$HOST/$NEW_INDEX" | jq -e --arg new "$NEW_INDEX" '
  (keys == [$new]) and (.[$new].aliases == {})' >/dev/null || fail "Destination must be an exact index with no aliases."
json_request -X POST "$HOST/$NEW_INDEX/_refresh" | check_shards
[[ "$(count_index "$NEW_INDEX")" == "0" ]] || fail "Destination is not empty. Choose a new index and inspect the partial copy."
json_request -X POST "$HOST/$OLD_INDEX/_refresh" | check_shards
OLD_COUNT=$(count_index "$OLD_INDEX")

BODY=$(jq -nc --arg old "$OLD_INDEX" --arg new "$NEW_INDEX" \
  '{source:{index:$old,size:1000},dest:{index:$new,op_type:"create"}}')
printf 'Starting one asynchronous copy. If no task ID returns, inspect GET /_tasks?actions=*reindex&detailed=true before retrying.\n'
START=$(json_request -X POST "$HOST/_reindex?wait_for_completion=false&slices=auto&requests_per_second=500" --data "$BODY")
TASK=$(printf '%s' "$START" | jq -er '.task | select(type == "string" and test("^[A-Za-z0-9_-]+:[0-9]+$"))') || fail "Missing or invalid task ID; inspect running tasks before retrying."
printf 'Task: %s\n' "$TASK"

while true; do
  RESULT=$(json_request "$HOST/_tasks/$TASK")
  printf '%s' "$RESULT" | jq -e '.completed | type == "boolean"' >/dev/null || fail "Task response has no completed flag."
  if [[ "$(printf '%s' "$RESULT" | jq -r '.completed')" == "true" ]]; then break; fi
  printf 'Copy is still running. Waiting 5 seconds...\n'
  sleep 5
done
printf '%s' "$RESULT" | jq -e '
  .response | type == "object" and .timed_out == false and .failures == [] and
    .version_conflicts == 0 and (.total | type == "number") and
    .created == .total and .updated == 0 and .deleted == 0 and .noops == 0' >/dev/null \
  || { printf '%s\n' "$RESULT" >&2; fail "Task completed without a clean full-copy result. Inspect it; do not cut over."; }

check_source_block
check_alias
json_request -X POST "$HOST/$NEW_INDEX/_refresh" | check_shards
FINAL_OLD_COUNT=$(count_index "$OLD_INDEX")
NEW_COUNT=$(count_index "$NEW_INDEX")
CREATED=$(printf '%s' "$RESULT" | jq -r '.response.created')
[[ "$OLD_COUNT" == "$FINAL_OLD_COUNT" && "$OLD_COUNT" == "$NEW_COUNT" && "$OLD_COUNT" == "$CREATED" ]] \
  || fail "Count mismatch: source before=$OLD_COUNT, source now=$FINAL_OLD_COUNT, destination=$NEW_COUNT, task created=$CREATED."
printf 'Copy checks passed: %s documents. The alias still points to %s.\n' "$NEW_COUNT" "$OLD_INDEX"
printf 'Next: compare document contents and application queries, restore intended settings, wait for replicas, and review the manual alias swap.\n'

Version compatibility

FeatureAvailable sinceNotes
Single type per index (no _type)7.0Multi-type indices are gone. References to types in older tutorials are obsolete.
Composable index templates7.8Old index_template API replaced by index_templates + component_templates.
Searchable snapshots7.10Mount a snapshot as a read-only index in the frozen tier.
Runtime fields7.11Compute fields at query time from _source or other fields. Cheap mapping additions.
dense_vector indexed for kNN8.0Required for the knn query.
ESQL8.11General-availability piped query language. Major addition.
semantic_text field type8.15Embedding inference at index and query time, no external embedding step.
Elasticsearch 8.162024License returned to open AGPL + ELv2 alongside the existing free Basic.

For specific upgrade walkthroughs, the official Elasticsearch upgrade documentation is the source of truth. Always snapshot before upgrading.

Common mistakes

The bugs I have shipped or seen in code review.

Searching a keyword field with match, or a text field with term. A match runs the value through the analyzer (lowercase, tokenize); a term does not. If your category field is keyword, { "match": { "category": "Footwear" } } will look for the analyzed form, which a keyword field never produced. Use term. Conversely, term against a text field looks for the exact analyzed token (often lowercased), so { "term": { "title": "Headphones" } } misses Headphones if the analyzer lowercased it to headphones.

Using from/size to paginate past the 10,000-result wall. The default index.max_result_window caps from + size at 10,000 because deep pagination forces every shard to maintain a deep priority queue. Raising the setting is almost always the wrong fix. Use search_after with a unique sort field (usually _id as a tiebreaker) or a Point In Time (PIT) for stable cursor pagination.

Sorting on a text field. Text fields do not support sorting unless you enable fielddata: true (which loads every term into memory). The correct fix is to add a keyword subfield in the mapping (fields: { keyword: { type: "keyword" } }) and sort on name.keyword instead.

Forgetting to refresh after indexing in a test. Elasticsearch refreshes every second by default. If your test indexes a doc and immediately queries it back, the doc is not yet searchable. Append ?refresh=true to the index call, or call POST /:index/_refresh. Do NOT set refresh_interval to a tiny value in production; the cost in segment count is brutal.

Letting unmapped fields run wild. Without an explicit mapping, Elasticsearch auto-detects types from the first document. A field that holds "42" on doc 1 and 42 on doc 2 will end up text and queries with term fail in confusing ways. Define mappings up front for anything that matters.

Treating shards as cheap. Each shard is a Lucene index with overhead. Hundreds of small shards per node will starve heap. The general guidance: 10-50GB per shard for search workloads, fewer larger shards over more smaller ones, total shards per node roughly 20 × heap_in_GB.

Running a single-node cluster in production. A one-node cluster has number_of_replicas: 1 by default and cannot allocate the replica anywhere; cluster status sits at yellow. Either set replicas to 0 (knowing you have no redundancy) or run at least two data nodes. Don't ignore the yellow.

Snapshotting without a registered repository. Snapshots require a repository registered ahead of time; PUT /_snapshot/:repo once, then PUT /_snapshot/:repo/:snapshot. Many teams discover at recovery time that they never set this up. Test the restore path before you need it.

Frequently asked questions

Elasticsearch is a distributed search and analytics engine. It's the right tool when you need full-text search (a product catalog, a knowledge base, a log explorer), faceted browsing (filter by brand, price range, category), or analytics over high-cardinality data (count error rates per host per minute, percentile latencies).

It is the WRONG tool for primary transactional storage. Use a real database (PostgreSQL, MySQL) for the source of truth and index a subset of fields into Elasticsearch for search.

Relational databases optimize for ACID transactions, foreign keys, joins, and precise queries. Elasticsearch optimizes for full-text relevance ranking, faceted aggregations across millions of documents, and horizontal scale via sharding.

Practical differences: Elasticsearch has no real joins (denormalize at index time), no transactions across documents, eventual consistency on writes (one-second default refresh), and a schema that allows mixed types per index if you're not careful. The wins are ranked full-text search, fast aggregations, and easy horizontal scaling.

An index is a logical namespace for documents (conceptually like a SQL table). A document is a single JSON object stored in an index, identified by an `_id`. A shard is the physical unit: each index has 1 or more primary shards, each of which is a Lucene index living on a node.

You read and write at the index level; Elasticsearch routes operations to the right shard automatically. You scale by adding shards (split an index across more nodes) or adding replicas (more read throughput, redundancy).

Two paths. The simplest is Docker:

docker run -p 9200:9200 -e "discovery.type=single-node" -e "ELASTIC_PASSWORD=changeme" docker.elastic.co/elasticsearch/elasticsearch:9.0.0

Then run a one-off Kibana container against the same network, or just use `curl` directly. For a long-running setup, install the package on your OS (apt / yum / brew) so it runs as a service with proper systemd integration. The bundled `elasticsearch-reset-password -u elastic` resets the initial password whenever you lose it.

Most slow searches fall into one of four buckets:

  • Wildcard / regex queries on `text` fields: `*foo*` style queries scan every term. Use a properly mapped `keyword` field, or `wildcard` field type for native wildcard support.
  • Deep pagination: `from: 9000, size: 100` forces every shard to sort and ship 9100 docs. Switch to `search_after` or PIT.
  • Sorting on an analyzed field: Sort on the `.keyword` subfield instead.
  • Too many shards: A query fans out to every shard of the queried indices. Consolidate small indices (use rollover or reindex) so a query hits a sane number of shards.

If too MANY docs match, your query is probably underusing `filter` clauses. Move binary conditions out of `must` into `filter` and the result set tightens up.

Both started from the same Lucene-based codebase; OpenSearch forked in 2021 after the Elastic license change, and Amazon maintains it. In 2024 Elastic added AGPL back to Elasticsearch (it landed in the 8.16 release line) alongside the existing open Basic license, so the licensing reason to fork is mostly gone.

Today: Elasticsearch leads on newer search features (vector search, ESQL, semantic_text). OpenSearch leads on AWS-managed integration (if you're on AWS, Amazon OpenSearch Service is cheaper to operate than self-managed Elastic on EC2). The APIs overlap heavily; client code that targets 7.x-compatible endpoints generally runs on both, but new Elastic-only features won't.

match runs your query through the analyzer of the target field (lowercase, tokenize, remove stop words depending on the analyzer). It is the right query for `text` fields and full-text search.

term does NOT run the analyzer. It looks for an exact token in the inverted index. It is the right query for `keyword` fields, IDs, enums, booleans, dates, and IP fields.

The most common bug is querying a `keyword` field with `match` (works by accident sometimes) or a `text` field with `term` (silently misses everything that the analyzer normalized). Check the mapping with `GET /:index/_mapping` before debugging further.

Yes. Use each Kibana Dev Tools request beside the curl version. Execute one complete request at a time, including its JSON body. After starting the asynchronous reindex, poll the returned task ID and verify successful completion before moving to validation or alias cutover.

No. Create and inspect the destination yourself. Reindex copies source documents; it does not reproduce the source index configuration. Matching index templates may still apply to a newly created destination, so check its actual settings and aliases.

The alias keeps routing them to the old index until cutover, and the copy may not include them. Pause and queue writes for the entire migration, or use durable change capture and an ordered cutover protocol. Updates and deletes matter as much as new documents.

Save the task value returned by POST /_reindex?wait_for_completion=false, then request GET /_tasks/<task_id>. Wait for completed: true and inspect error, response.failures, timed_out, conflicts, and document counters. Completion alone does not mean success.

There is no reliable duration based on document count alone. Document size, analyzers, shard layout, storage, replicas, throttling, and competing traffic all affect throughput. Measure a representative copy and monitor the task and cluster. Slicing may help, but it can also increase production load.

Yes. The reindex request supports a top-level script alongside source and dest, or a pipeline specified under dest. Test transformations separately and adjust validation for intentional changes to IDs, fields, or document counts.

Types were removed in Elasticsearch 7.0. Before that, an index could contain documents of multiple "types" sharing the same mapping. The feature caused more confusion than value and was deprecated in 6.x.

The migration was to give each former type its own index (one index per type), or use a discriminator field within a single index. Any tutorial that uses URLs of the form /:index/:type/_search is from 6.x or older and the code will not run on a modern cluster.

See also

External references: Elasticsearch official documentation is the source of truth for endpoint behavior and version-specific changes. The Elastic Search Labs blog covers the newer ESQL, vector search, and semantic_text features in depth.

Sources

Authoritative references this article was fact-checked against.

TagsElasticsearchSearchQuery DSLESQLVector SearchREST APIReindexAliasesKibanaCheat Sheet

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

Regex Cheat Sheet including regex symbols, ranges, grouping, assertions, syntax tables, examples, matches, and compatibility tables. Definitive Regular Expressions Quick Reference!

Regex Cheat Sheet

A regular expression is a pattern that describes a set of strings. This cheat sheet covers character classes, anchors, quantifiers, groups, lookarounds and flags, with per-engine compatibility tables.

Open vintage hardcover reference manual on a dark slate desk, dense columned print on warm cream pages lit by a single warm amber side lamp

MySQL Cheat Sheet

MySQL cheat sheet covering CLI commands, database and table operations, joins, indexes, backups, user management, and transactions, with version notes for 5.7, 8.0, and 8.4.

ffmpeg cheat sheet: -c copy remux, trim, crop and cropdetect, palettegen GIFs, WebM to MP4, reverse, loudnorm volume, x264/x265/AV1 -crf, speed, concat, fixes.

The ffmpeg Command Cheat Sheet

A scannable ffmpeg reference: stream-copy without re-encoding, trim and cut, resize, crop and cropdetect, black and white (grayscale and sepia), extract or remove audio, normalize loudness with loudnorm, high-quality GIFs with palettegen, WebM to MP4 and back, change speed with setpts and atempo, reverse a clip, concat, subtitles, and the fixes for the errors you actually hit.