fix: wrap scroll-search --query under "query" in request body#215
Merged
Conversation
The scroll-search helper was sending the raw --query JSON as the full
request body, so `--query '{"match_all":{}}'` hit ES as
`{"match_all":{}}` and failed with a parsing_exception. Wrap --query
content under a `query` key to match the behavior of `es search --query`
and user expectations. --input-file and stdin continue to be treated as
the full search body so callers can still supply query + sort + aggs
together.
Fixes #169
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
margaretjgu
approved these changes
Apr 22, 2026
This was referenced Apr 22, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #169.
elastic es helpers scroll-search --query '{"match_all":{}}'was failing withparsing_exception: Unknown key for a START_OBJECT in [match_all]because the helper sent the raw parsed--queryJSON as the entire request body. Elasticsearch expects the query clause wrapped under"query".This aligns
--querysemantics with the generatedes search --querycommand and the help text example users would reasonably try.Changes
src/es/helpers/scroll-search.ts:--querycontents are now wrapped as{ query: <parsed> }before being sent.--input-fileand stdin continue to be treated as a full search body so callers can still includequery+sort+aggstogether. Updated flag descriptions to make the distinction explicit.test/es/helpers/scroll-search.test.ts: updated the two flag-semantics tests to assert the new body shapes (--querywraps;--input-fileis passed through verbatim). The other 10 tests are unchanged.Test plan
node --import tsx/esm --test test/es/helpers/scroll-search.test.ts— 12/12 passnpx tsc --noEmit— cleanelastic es helpers scroll-search --index test-scroll --query '{"match_all":{}}'Fetched N documents in Xmssummary instead ofparsing_exception.--input-filewith{"query":{"match_all":{}},"sort":[{"_doc":"asc"}]}still works.