Database
Elasticsearch
Elasticsearch curl commands for search engine management.
29 commands
Windows
MacOS
Linux
#search-engine
#analytics
Cluster Health
Check cluster health
curl -s localhost:9200/_cluster/health?pretty
List all nodes
curl -s localhost:9200/_cat/nodes?v
List all indices
curl -s localhost:9200/_cat/indices?v
List all shards
curl -s localhost:9200/_cat/shards?v
Show cluster statistics
curl -s localhost:9200/_cluster/stats?pretty
Show disk allocation
curl -s localhost:9200/_cat/allocation?v
Index Management
Create an index
curl -X PUT localhost:9200/my-index
Delete an index
curl -X DELETE localhost:9200/my-index
Update index settings
curl -X PUT localhost:9200/my-index/_settings -H 'Content-Type: application/json' -d '{"number_of_replicas":2}'
Show index mapping
curl -s localhost:9200/my-index/_mapping?pretty
Close an index
curl -X POST localhost:9200/my-index/_close
Open a closed index
curl -X POST localhost:9200/my-index/_open
Document Operations
Index a document
curl -X POST localhost:9200/my-index/_doc -H 'Content-Type: application/json' -d '{"title":"test"}'
Get document by ID
curl -s localhost:9200/my-index/_doc/1?pretty
Delete document by ID
curl -X DELETE localhost:9200/my-index/_doc/1
Update a document
curl -X POST localhost:9200/my-index/_update/1 -H 'Content-Type: application/json' -d '{"doc":{"title":"updated"}}'
Count documents in index
curl -s localhost:9200/my-index/_count?pretty
Search
Search all documents
curl -s localhost:9200/my-index/_search?pretty
Simple query string search
curl -s localhost:9200/my-index/_search?q=title:test
Match query
curl -X POST localhost:9200/my-index/_search -H 'Content-Type: application/json' -d '{"query":{"match":{"title":"test"}}}'
Bool query
curl -X POST localhost:9200/my-index/_search -H 'Content-Type: application/json' -d '{"query":{"bool":{"must":[{"match":{"title":"test"}}]}}}'
Range query
curl -X POST localhost:9200/my-index/_search -H 'Content-Type: application/json' -d '{"query":{"range":{"date":{"gte":"2025-01-01"}}}}'
Aggregations
Terms aggregation
curl -X POST localhost:9200/my-index/_search -H 'Content-Type: application/json' -d '{"size":0,"aggs":{"by_status":{"terms":{"field":"status.keyword"}}}}'
Average aggregation
curl -X POST localhost:9200/my-index/_search -H 'Content-Type: application/json' -d '{"size":0,"aggs":{"avg_price":{"avg":{"field":"price"}}}}'
Date histogram
curl -X POST localhost:9200/my-index/_search -H 'Content-Type: application/json' -d '{"size":0,"aggs":{"by_date":{"date_histogram":{"field":"date","calendar_interval":"month"}}}}'
Reindex data
curl -X POST localhost:9200/_reindex -H 'Content-Type: application/json' -d '{"source":{"index":"old"},"dest":{"index":"new"}}'
Quick Commands
Check Elasticsearch cluster health status
curl -s localhost:9200/_cluster/health?pretty
List all indices with details
curl -s localhost:9200/_cat/indices?v
Simple query string search
curl -s localhost:9200/my-index/_search?q=title:test