Skip to content

es index/create: accept REST-style bodies (follow-up to #95 / #130) #360

Description

@l-trotta

#130 fixed #95 on the request side (the document wrapper is correctly stripped before sending to ES via BODY_ROOT_FIELDS). But the input-validation layer still requires the wrapper, so REST-style bodies — the shape used everywhere in Elastic docs, tutorials, and Dev Tools — fail before the request builder runs.

Reproducer (CLI 0.1.1):

$ echo '{"name":"test"}' | elastic es index --index test --id 1
Error: input validation failed:
✖ Invalid input: expected nonoptional, received undefined
  → at document

Currently the user must wrap as {"document": {"name":"test"}}.

Suggested fix: when a schema field is registered in BODY_ROOT_FIELDS with rule '*' (e.g. document), treat a body that doesn't contain that key as the implicit value of it. Applies to es index, es create, es update (doc), inference APIs, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions