`es search --input-file` rejects the `sort` shorthand `[{"field":"asc"}]`
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 63/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- json, typescript
- Domaine
- cli
Piste de recherche
Start with the reproduction command using --input-file -, then read src/lib/json-schema-args.ts around lines 133-157 and src/factory.ts around lines 724-737 to see how unions are resolved and relaxed. Follow the sort value into _types__SortCombinations / _types__FieldSort from @elastic/schemas, then decide whether a CLI-side relaxation should mirror the existing object/array workaround or whether the schema fix must land upstream. Done means [{"@timestamp":"asc"}] passes validation for file-supplied bodies as it already does with --no-validate.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
Elasticsearch accepts "sort":[{"@timestamp":"asc"}], the form used throughout its search docs. The CLI's client-side validation rejects it when the body comes from --input-file.
Reproduction (v0.7.0, also unchanged on main at fd3359d)
echo '{"size":1,"sort":[{"@timestamp":"asc"}]}' | elastic es search --index my-index --input-file -
# Error: input validation failed:
# ✖ must be string → at .sort
# ✖ must be object → at .sort
# ✖ must be string → at .sort[0]
# ✖ must be object → at .sort[0]['@timestamp']
# exit 1
Body sort |
CLI | Elasticsearch directly |
|---|---|---|
[{"@timestamp":"asc"}] |
validation error, exit 1 | OK |
[{"@timestamp":{"order":"asc"}}] |
OK | OK |
["@timestamp"] |
OK | OK |
shorthand with --no-validate |
OK | OK |
"@timestamp:asc" |
passes validation, then a shard failure (No mapping found for [@timestamp:asc]), HTTP 200, exit 0 |
same shard failure |
Sort shorthand nested inside a top_hits aggregation is accepted.
Mechanism
_types__SortCombinations in @elastic/schemas 0.10.0 accepts a string or _types__SortOptions. The additional properties of _types__SortOptions must be _types__FieldSort, which is an object, so the value "asc" fails. src/lib/json-schema-args.ts:133-157 resolves this union to the CLI string type, so the object/array relaxation in src/factory.ts:724-737 doesn't apply to a file-supplied sort.
Root cause
The schema is stricter than the specification. The spec marks FieldSort with @shortcut_property order (sort.ts L43-L44): a FieldSort may be written as just its order value. @elastic/schemas 0.10.0 emits _types__FieldSort as object-only, so "asc" fails.
The same loss affects 25 shortcut types in the spec, including term and match queries. Those pass in the CLI only because query is object-typed and covered by the relaxation described under Mechanism. sort isn't, so this is where the gap shows.
Reported upstream: elastic/schemas-js#125. A CLI-side workaround is to relax sort the same way, or to pass --no-validate, which already works. The schema fix covers every shortcut type.
Expected
Accept SortOrder strings ("asc" / "desc") as values in the sort object map, as the Elasticsearch spec does.
Related
- elastic/cli#330 and elastic/cli#350 fixed the
--sort field:directionflag. That flag works. This report is about the--input-filebody. - elastic/cli#331: a different field (
_sourcearrays) rejected by file-input validation.
- Langage dominant
- TypeScript
- Étoiles
- 53
- Forks
- 28
- Merge moyen
- 4 j 12 h
- PR mergées (30 j)
- 61
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de elastic/cli
-
tracking
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
Les mainteneurs répondent en général sous 1 jour
-
feat: ship skills/elastic/SKILL.md for agent invocationPeut-être pris @onatozmenn l’a pris il y a 32 jours. Ouverteenhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
elastic/cli#628 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
elastic/cli#617 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
tracking
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de elastic/cli
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
better-auth/better-auth#12132 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
o8 next debug build aborts on Glass to Dark appearance switch (nil identifier messaged before check)Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
hurttlocker/o8#5112 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
webrecorder/wabac.js#386 ·
-
needs-triage
Difficulté 1/5 1-3 heures Accessibilité débutants 92/100
agent-of-empires/agent-of-empires#5098 · 1 commentaire · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour