Summary
Running elastic es index --index <index> --document '{}' without providing --id fails with an HTTP method error. The CLI sends a PUT request to /<index>/_doc, but when no document ID is specified, Elasticsearch expects a POST request (to auto-generate an ID). Providing --id works correctly because PUT is valid for /<index>/_doc/<id>.
Environment
- CLI:
0.1.0-alpha.1 (elastic version)
- ES:
9.3.3 (Docker)
- OS:
Darwin 25.4.0 arm64
Repro
elastic es indices create --index test-index
elastic es index --index test-index --document '{"title":"hello"}'
Actual result
Error: Incorrect HTTP method for uri [/test-index/_doc] and method [PUT], allowed: [POST]
Expected result
The document should be indexed with an auto-generated ID:
{
"_index": "test-index",
"_id": "<auto-generated>",
"_version": 1,
"result": "created"
}
Control / workaround
Providing an explicit --id works:
elastic es index --index test-index --id doc1 --document '{"title":"hello"}'
# succeeds
Direct curl with POST (no ID) also works:
curl -u elastic:changeme -X POST "http://localhost:9200/test-index/_doc" \
-H 'Content-Type: application/json' \
-d '{"title":"hello"}'
# succeeds, autogenerates id
Summary
Running
elastic es index --index <index> --document '{}'without providing--idfails with an HTTP method error. The CLI sends a PUT request to/<index>/_doc, but when no document ID is specified, Elasticsearch expects a POST request (to auto-generate an ID). Providing--idworks correctly because PUT is valid for/<index>/_doc/<id>.Environment
0.1.0-alpha.1(elastic version)9.3.3(Docker)Darwin 25.4.0 arm64Repro
elastic es indices create --index test-index elastic es index --index test-index --document '{"title":"hello"}'Actual result
Expected result
The document should be indexed with an auto-generated ID:
{ "_index": "test-index", "_id": "<auto-generated>", "_version": 1, "result": "created" }Control / workaround
Providing an explicit
--idworks:Direct curl with POST (no ID) also works: