Skip to content

bug: es index without --id uses PUT instead of POST #168

Description

@margaretjgu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions