`es search --input-file` drops top-level `aggs` (and any unrecognised key) without an error
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- elasticsearch, typescript
- Área
- cli
Línea de trabajo
Start by reproducing with the body.json snippet and comparing the CLI result with the direct Elasticsearch call. Then read src/es/request-builder.ts:163-169 and src/lib/json-schema-args.ts:193-206 to see how only schema-declared keys are copied, and check src/lib/ajv-validate.ts for validation behavior. Decide between forwarding and rejecting unknown top-level keys, and handle aggs as an alias of aggregations; done means aggs works and a misspelt key no longer silently returns unfiltered results, with tests for both.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Related to elastic/cli#803
Summary
The ES request builder rebuilds the request body from the keys declared in the command's schema. Any other top-level key in --input-file is dropped before the request is sent. The command exits 0 and prints no warning.
The most common case is aggs. Elasticsearch accepts both aggs and aggregations, and most docs and examples use aggs. The search schema declares only aggregations, so a body written with aggs returns hits and no aggregations key.
A misspelt key fails the same way. Elasticsearch would answer 400 to a misspelt query; the CLI sends the request without it and returns unfiltered results.
Reproduction (v0.7.0, also unchanged on main at fd3359d)
cat > body.json <<'JSON'
{"size":0,"aggs":{"by_day":{"date_histogram":{"field":"@timestamp","calendar_interval":"day"}}}}
JSON
elastic es search --index my-index --input-file body.json | jq 'has("aggregations")'
# false (exit 0, empty stderr)
curl -s -H "Authorization: ApiKey $KEY" -H 'Content-Type: application/json' \
"$ES/my-index/_search" -d @body.json | jq 'has("aggregations")'
# true
jq '.aggregations=.aggs | del(.aggs)' body.json | elastic es search --index my-index --input-file - | jq 'has("aggregations")'
# true
Misspelt key:
echo '{"qeury":{"term":{"event.action":"no-such-value"}}}' | elastic es count --index my-index --input-file -
# returns the full index count, exit 0
# Elasticsearch directly: 400 "request does not support [qeury]"
Scope observed
| Command | Unknown top-level key |
|---|---|
es search |
dropped |
es count |
dropped |
es esql query |
dropped |
es async-search submit |
dropped (checked against a local capture server: body keys ["query","size"]) |
es msearch |
bodies inside searches pass through, including aggs |
kb … |
forwarded (src/kb/request-builder.ts) |
Nested keys are not affected: sub-aggregations under aggregations keep aggs.
Mechanism
src/es/request-builder.ts:163-169copies only schema-derived arguments (src/lib/json-schema-args.ts:193-206) into a new body. Keys outside the schema never reach it.search.request.jsonin@elastic/schemas0.10.0 declaresproperties.aggregationsbut noaggs.- AJV does not remove the key (
src/lib/ajv-validate.tssets noremoveAdditional), so--no-validatemakes no difference.
Conflicts with AGENTS.md
The input rules in AGENTS.md ("Command Authoring Requirements" → "Input") say:
Reject unknown keys: Input with undefined keys MUST produce a validation error naming the unknown field(s). Silent stripping is not acceptable.
For ES commands, an unknown top-level key is neither rejected nor sent. Applied as written, that rule would make aggs a validation error, which still breaks the most common Elasticsearch body shape. Accepting aggs as an alias of aggregations, and rejecting other unknown keys, satisfies both.
Root cause
Two layers, both needed:
@elastic/schemasdoesn't carry the spec's alias. The specification marksaggregationswith@aliases aggs(SearchRequest.tsL414-L419). The JSON Schema output drops it, soaggsreaches the CLI as an unknown key. Reported upstream: elastic/schemas-js#125.- The ES request builder drops unknown keys instead of rejecting them (see Mechanism). This is a CLI defect independent of the schemas: a misspelt
queryreturns unfiltered results with exit 0.
If the upstream fix emits aggs as a declared property, the CLI picks it up with no change. If it adds an annotation instead, the CLI must read that annotation. Fixing (2) turns any remaining unknown key into a validation error, as AGENTS.md requires.
Expected
Either option would avoid wrong results with exit 0:
- Forward unknown top-level body keys, as the Kibana builder does, and let Elasticsearch accept or reject them. At minimum, accept
aggsas an alias ofaggregations. - Or fail (or warn on stderr) when
--input-filecontains a top-level key the command will not send.
Related
- elastic/cli#170 and elastic/cli#223: rejection of unknown fields, fixed by moving to passthrough schemas. This report is the opposite symptom: no rejection, the key is silently omitted.
- elastic/cli#699: malformed JSON passing validation. It mentions
aggs, but not this omission. - elastic/cli#786: request-routing unification. It keeps service-specific behaviour, so it doesn't appear to change this.
- Lenguaje dominante
- TypeScript
- Estrellas
- 53
- Forks
- 28
- Merge medio
- 4 d 12 h
- PR fusionados (30 d)
- 61
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de elastic/cli
-
Extension --help prints root help instead of running the extensionPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertotracking
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
feat: ship skills/elastic/SKILL.md for agent invocationPosiblemente ocupada @onatozmenn la tomó hace 33 días. Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
elastic/cli#628 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
elastic/cli#617 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
tracking
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de elastic/cli
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Northeastern-Electric-Racing/FinishLine#4660 ·
Los mantenedores suelen responder en 2 días
-
BeOS .json missingAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
mihaip/infinite-mac#475 ·
-
Let TypeScript accept an initial object in ReactiveDictPosiblemente ocupada @yograj-vijay-yadav la tomó hoy. Abiertobug good first issue help wanted workshop
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
meteor/meteor#14919 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
marmelab/atomic-crm#401 ·
Los mantenedores suelen responder en 1 día
-
account: profile
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 5 días