Database cheatsheet
Elasticsearch 9 Cheatsheet
curl requests for indexes, documents, searches, bulk loads and cluster health. Security is on by default, so the examples authenticate.
Cluster and health
- Check that the cluster is up — Return the cluster name and Elasticsearch version. Set ELASTIC_PASSWORD first, and point --cacert at your cluster's CA certificate.
- Check cluster health — Show the status: green, yellow or red.
- List nodes — Show nodes with their roles, load and memory.
- List indices — Show indices with health, document counts and size.
- List shards — Show where every shard is allocated.
- Explain unassigned shards — Ask why a shard is not allocated.
Indices and mappings
- Create an index — Create an index with explicit settings.
- Define field types — Add a mapping so fields are analyzed the way you want.
- Read a mapping — Show the field types of an index.
- Add an alias — Point an alias at an index, so applications don't depend on the index name.
- Copy documents to a new index — Copy documents from one index to another, for example after changing a mapping.
- Delete an index — Delete an index and all its documents.
Documents
- Index a document with an ID — Create or replace a document.
- Index a document with a generated ID — Let Elasticsearch choose the ID.
- Get a document — Fetch a single document by its ID.
- Update fields — Merge fields into an existing document.
- Delete a document — Delete a single document by its ID.
- Load many documents — Index many documents from a newline-delimited JSON file. Each action line is followed by its document, and the file ends with a newline.
- Count documents — Count the documents in an index.
Searching
- Return everything — Return the first 10 documents.
- Full-text search — Find documents whose name matches the text, ranked by relevance.
- Exact match on a keyword — Match a keyword field exactly.
- Combine conditions — Require a text match and filter by price without affecting the score.
- Sort and paginate — Return 5 results starting at the tenth, cheapest first.
- Aggregate — Compute the average price without returning documents.
- See how text is analyzed — Show the tokens the standard analyzer produces.
Related cheatsheets
- DuckDB 2 cheatsheet — Query CSV, Parquet and DataFrames with SQL from Python or the duckdb command line, without running a server.
- MongoDB 8 cheatsheet — mongosh shell commands for documents, queries, aggregation, indexes, backups and administration.
- MySQL 8.4 cheatsheet — mysql client, backup and maintenance commands for MySQL 8.4.
- PostgreSQL 18 cheatsheet — psql, backup and maintenance commands for PostgreSQL 18.
- Redis 8 cheatsheet — redis-cli and core commands for keys, data structures and server administration.
- SQLite 3 cheatsheet — sqlite3 shell dot-commands, pragmas, import and export, and the SQL you use most.