Skip to main content
Databases

Elasticsearch & OpenSearch REST API

Production

Index management, boolean search queries, match aggregations, cluster health, and mapping configurations.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Elasticsearch & OpenSearch REST API Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (16 Total Commands).

16+ Verified Recipes
Cluster Health_cluster/health
curl -X GET "http://localhost:9200/_cluster/health?pretty"

Inspect cluster health status (green, yellow, red) and unassigned shard counts.

Indices List/_cat/indices
curl -X GET "http://localhost:9200/_cat/indices?v&s=docs.count:desc"

List all indices with doc counts, storage sizes, and health status sorted by size.

Create Index MappingPUT /<index>
curl -X PUT "http://localhost:9200/products" -H 'Content-Type: application/json' -d '{ "mappings": { "properties": { "title": { "type": "text" }, "price": { "type": "float" }, "category": { "type": "keyword" } } } }'

Create an index with explicit text and keyword field type mappings.

Search & Query DSL_search
curl -X POST "http://localhost:9200/products/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [{ "match": { "title": "wireless keyboard" } }], "filter": [{ "range": { "price": { "lte": 50 } } }] } } }'

Execute structured boolean query combining full-text relevance with exact filter caching.

Aggregations"aggs":
curl -X POST "http://localhost:9200/products/_search" -H 'Content-Type: application/json' -d '{ "size": 0, "aggs": { "categories": { "terms": { "field": "category" } }, "avg_price": { "avg": { "field": "price" } } } }'

Compute term buckets and metric averages without returning raw documents.

Document Ingestion/_doc/<id>
curl -X POST "http://localhost:9200/products/_doc/101" -H 'Content-Type: application/json' -d '{"title":"Ergonomic Mouse","price":29.99,"category":"electronics"}'

Index or replace a single JSON document by explicit ID.

Shards & Replicas/_settings
curl -X PUT "http://localhost:9200/products/_settings" -H 'Content-Type: application/json' -d '{"number_of_replicas": 2}'

Dynamically adjust replica count for high availability and read throughput.

Cluster Telemetry_nodes/stats
curl -X GET "http://localhost:9200/_nodes/stats/jvm,os,process?pretty"

Inspect cluster node JVM heap memory utilization, garbage collection pauses, and operating system CPU load.

Index Reindexing_reindex
curl -X POST "http://localhost:9200/_reindex" -H 'Content-Type: application/json' -d '{"source": {"index": "v1_orders"}, "dest": {"index": "v2_orders"}}'

Execute background server-side reindexing to apply updated field mappings or token analyzers without downtime.

Zero-Downtime Aliases_aliases
curl -X POST "http://localhost:9200/_aliases" -H 'Content-Type: application/json' -d '{"actions": [{"remove": {"index": "v1_orders", "alias": "orders"}}, {"add": {"index": "v2_orders", "alias": "orders"}}]}'

Atomically switch index alias pointer from legacy index to newly built index without dropped queries.

Multi-Field Boostingmulti_match, ^3
curl -X POST "http://localhost:9200/products/_search" -H 'Content-Type: application/json' -d '{"query": {"multi_match": {"query": "mechanical keyboard", "fields": ["title^3", "description"], "type": "best_fields"}}}'

Search across multiple text fields with 3x relevance boost weighting on title matches.

Bulk Ingestion_bulk, NDJSON
curl -X POST "http://localhost:9200/_bulk" -H 'Content-Type: application/x-ndjson' --data-binary @bulk_data.ndjson

Stream high-throughput NDJSON document batches to maximize cluster write throughput.

Analyzer Diagnostics_analyze
curl -X POST "http://localhost:9200/products/_analyze" -H 'Content-Type: application/json' -d '{"analyzer": "standard", "text": "High-performance Elasticsearch cluster"}'

Inspect tokenizer splitting, lowercase filtering, and stemming outputs for given text strings.

Shard Diagnostics_cat/shards
curl -X GET "http://localhost:9200/_cat/shards?v&s=state:desc"

List shard allocation, replica status, and primary node placement to troubleshoot unassigned shards.

Highlightinghighlight
curl -X POST "http://localhost:9200/products/_search" -H 'Content-Type: application/json' -d '{"query": {"match": {"description": "wireless"}}, "highlight": {"fields": {"description": {}}}}'

Execute search query returning HTML tagged fragments matching query tokens for frontend search previews.

Segment Optimization_forcemerge
curl -X POST "http://localhost:9200/products/_forcemerge?max_num_segments=1"

Force merge Lucene segment files on read-only indices to reclaim deleted document space and accelerate search.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Elasticsearch & OpenSearch REST API: Command Groups & Quick Index

16 indexed entries across 16 sections
Cluster Health1 items
Indices List1 items
Create Index Mapping1 items
Search & Query DSL1 items
Aggregations1 items
Document Ingestion1 items
Shards & Replicas1 items
Cluster Telemetry1 items
Index Reindexing1 items
Zero-Downtime Aliases1 items
Multi-Field Boosting1 items
Bulk Ingestion1 items
Analyzer Diagnostics1 items
Shard Diagnostics1 items
Highlighting1 items
Segment Optimization1 items

Highlighted Flags & Syntax Examples in Elasticsearch & OpenSearch REST API

curl -X GET "http://localhost:9200/_cluster/health?pretty"

Inspect cluster health status (green, yellow, red) and unassigned shard counts.

Flags: _cluster/health
curl -X GET "http://localhost:9200/_cat/indices?v&s=docs.count:desc"

List all indices with doc counts, storage sizes, and health status sorted by size.

Flags: /_cat/indices
curl -X PUT "http://localhost:9200/products" -H 'Content-Type: application/json' -d '{ "mappings": { "properties": { "title": { "type": "text" }, "price": { "type": "float" }, "category": { "type": "keyword" } } } }'

Create an index with explicit text and keyword field type mappings.

Flags: PUT /<index>
curl -X POST "http://localhost:9200/products/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [{ "match": { "title": "wireless keyboard" } }], "filter": [{ "range": { "price": { "lte": 50 } } }] } } }'

Execute structured boolean query combining full-text relevance with exact filter caching.

Flags: _search

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Elasticsearch & OpenSearch REST API.

What is the difference between text and keyword data types in Elasticsearch?

text fields undergo full-text analysis (tokenization, lowercasing, stemming) and are optimized for relevance matching. keyword fields are indexed verbatim without tokenization, making them ideal for exact filtering, sorting, and aggregations.

Why should queries in the bool filter clause be preferred over must when scoring is not needed?

filter clauses do not compute relevance scores (_score), allowing Elasticsearch to automatically cache filter bitsets in memory for lightning-fast repeated queries.

What causes unassigned shards in Elasticsearch and how do you resolve cluster yellow/red state?

A 'yellow' cluster means all primary shards are active but some replica shards cannot be assigned (often due to single-node clusters where replicas cannot live on the same host). A 'red' status indicates one or more primary shards are missing. Query 'GET /_cluster/allocation/explain' to inspect the exact failure reason (e.g. disk watermarks, node disconnections).

What is an inverted index and how does BM25 scoring calculate search relevance?

An inverted index maps every distinct tokenized word to the list of document IDs containing it. Okapi BM25 scores documents by calculating Term Frequency (TF, how often the word appears in the document with non-linear saturation), Inverse Document Frequency (IDF, penalizing common terms across the index), and document length normalization.

How does heap memory allocation (50% rule, 32GB compressed OOPs threshold) affect Elasticsearch performance?

Set JVM heap to at most 50% of available physical RAM (leaving the remaining 50% for OS Lucene filesystem page cache) and never exceed ~31GB. Staying below 31GB allows the JVM to use 32-bit Compressed Ordinary Object Pointers (Compressed OOPs), doubling effective memory addressable per pointer.

What is the difference between routing keys and default Murmur3 document sharding?

By default, Elasticsearch routes documents across shards using 'hash(_id) % number_of_shards', requiring search queries to fan out across all shards. By setting a custom routing key (e.g. 'routing=tenant_id'), all documents for that tenant reside on a single shard, allowing queries with that routing key to target a single shard directly.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets