All skills
Skillintermediate
Document API Reference
```bash # By ID es "my-index/_doc/abc123" | jq '._source'
Claude Code Knowledge Pack7/10/2026
Overview
Document API Reference
Get Document
# By ID
es "my-index/_doc/abc123" | jq '._source'
# Specific fields only
es "my-index/_doc/abc123?_source_includes=timestamp,message"
Index (Create/Replace) Document
# With specific ID (PUT = create or replace)
es "my-index/_doc/abc123" -XPUT -d '{
"timestamp": "2026-02-01T12:00:00Z",
"message": "Hello from Nox",
"level": "info"
}'
# Auto-generate ID (POST)
es "my-index/_doc" -XPOST -d '{
"timestamp": "2026-02-01T12:00:00Z",
"message": "Auto-ID document"
}'
Update Document
Partial update (merge fields):
es "my-index/_update/abc123" -XPOST -d '{
"doc": {
"level": "warn",
"updated_at": "2026-02-01T13:00:00Z"
}
}'
Script update (computed values):
es "my-index/_update/abc123" -XPOST -d '{
"script": {
"source": "ctx._source.retry_count += 1",
"lang": "painless"
}
}'
Upsert (create if missing, update if exists):
es "my-index/_update/abc123" -XPOST -d '{
"doc": {"counter": 1},
"upsert": {"counter": 1, "created": "2026-02-01T12:00:00Z"}
}'
Delete Document
es "my-index/_doc/abc123" -XDELETE
Delete by Query
es "my-index/_delete_by_query" -XPOST -d '{
"query": {
"range": {"@timestamp": {"lt": "now-90d"}}
}
}'
Update by Query
es "my-index/_update_by_query" -XPOST -d '{
"query": {"term": {"status": "pending"}},
"script": {
"source": "ctx._source.status = \\"expired\\"",
"lang": "painless"
}
}'
Multi-Get
es "_mget" -XPOST -d '{
"docs": [
{"_index": "my-index", "_id": "abc123"},
{"_index": "my-index", "_id": "def456"}
]
}'
Bulk API
The most efficient way to index many documents. Uses NDJSON format (newline-delimited JSON).
es "_bulk" -XPOST -H "Content-Type: application/x-ndjson" -d '
{"index": {"_index": "my-index", "_id": "1"}}
{"timestamp": "2026-02-01T12:00:00Z", "message": "first"}
{"index": {"_index": "my-index", "_id": "2"}}
{"timestamp": "2026-02-01T12:01:00Z", "message": "second"}
{"delete": {"_index": "my-index", "_id": "old-doc"}}
'
Bulk from file:
es "_bulk" -XPOST -H "Content-Type: application/x-ndjson" --data-binary @bulk-data.ndjson
Performance tips:
- Optimal bulk size: 5-15 MB per request
- Use
_bulkinstead of individual requests for >10 documents - Check response for
errors: trueand inspect individual item statuses