Elasticsearch 9 cheatsheet
Elasticsearch 9: Documents
7 common Elasticsearch 9 tasks.
Index a document with an ID
Create or replace a document.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt -X PUT "https://localhost:9200/products/_doc/1" -H "Content-Type: application/json" -d '{"name":"Laptop","sku":"LT-100","price":999.0}'
Index a document with a generated ID
Let Elasticsearch choose the ID.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt -X POST "https://localhost:9200/products/_doc" -H "Content-Type: application/json" -d '{"name":"Mouse","price":25.0}'
Get a document
Fetch a single document by its ID.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt "https://localhost:9200/products/_doc/1?pretty"
Update fields
Merge fields into an existing document.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt -X POST "https://localhost:9200/products/_update/1" -H "Content-Type: application/json" -d '{"doc":{"price":899.0}}'
Delete a document
Delete a single document by its ID.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt -X DELETE "https://localhost:9200/products/_doc/1"
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.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt -X POST "https://localhost:9200/_bulk" -H "Content-Type: application/x-ndjson" --data-binary @data.ndjson
Count documents
Count the documents in an index.
curl -u elastic:$ELASTIC_PASSWORD --cacert http_ca.crt "https://localhost:9200/products/_count?pretty"