Skip to content

fix: wrap scroll-search --query under "query" in request body#215

Merged
MattDevy merged 2 commits into
mainfrom
claude/inspiring-sutherland-4bcd4f
Apr 22, 2026
Merged

fix: wrap scroll-search --query under "query" in request body#215
MattDevy merged 2 commits into
mainfrom
claude/inspiring-sutherland-4bcd4f

Conversation

@MattDevy
Copy link
Copy Markdown
Contributor

Summary

Fixes #169.

elastic es helpers scroll-search --query '{"match_all":{}}' was failing with parsing_exception: Unknown key for a START_OBJECT in [match_all] because the helper sent the raw parsed --query JSON as the entire request body. Elasticsearch expects the query clause wrapped under "query".

This aligns --query semantics with the generated es search --query command and the help text example users would reasonably try.

Changes

  • src/es/helpers/scroll-search.ts: --query contents are now wrapped as { query: <parsed> } before being sent. --input-file and stdin continue to be treated as a full search body so callers can still include query + sort + aggs together. 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 (--query wraps; --input-file is 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 pass
  • npx tsc --noEmit — clean
  • Manual repro from the issue against a local ES 9.x:
    elastic es helpers scroll-search --index test-scroll --query '{"match_all":{}}'
    returns the document and the Fetched N documents in Xms summary instead of parsing_exception.
  • --input-file with {"query":{"match_all":{}},"sort":[{"_doc":"asc"}]} still works.

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
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 2.98s
✅ REPOSITORY gitleaks yes no no 8.81s
✅ REPOSITORY git_diff yes no no 0.11s
✅ REPOSITORY secretlint yes no no 2.29s
✅ REPOSITORY trivy yes no no 15.78s
✅ TYPESCRIPT eslint 2 0 0 2.87s

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@MattDevy MattDevy requested review from margaretjgu and ssh-esh April 22, 2026 13:08
@MattDevy MattDevy merged commit 60e9c45 into main Apr 22, 2026
17 checks passed
@MattDevy MattDevy deleted the claude/inspiring-sutherland-4bcd4f branch April 22, 2026 15:37
This was referenced Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: es helpers scroll-search --query fails with parsing exception on valid query

2 participants