Conversation
This commit introduces XContentFieldFilter, which applies field includes/excludes to XContent without having to realise the xcontent itself as a java map. SourceFieldMapper and ShardGetService are cut over to use this class
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| XContentBuilder builder = new XContentBuilder(contentType.xContent(), streamOutput); | ||
| XContentParser parser = contentType.xContent().createParser(parserConfig, originalSource.streamInput()); | ||
| builder.copyCurrentStructure(parser); | ||
| return BytesReference.bytes(builder); |
There was a problem hiding this comment.
XContentParser resource leak in parser-based filtering branch
Medium Severity
The XContentParser created at line 70 is never closed. XContentParser extends Closeable and wraps an input stream that needs proper cleanup. This resource leak occurs every time the filter is applied when excludes doesn't contain wildcards. The codebase pattern (visible in IndexAbstraction.java and IndexRouting.java) uses try-with-resources for parsers created with streamInput(), but this implementation omits that.
| XContentParser parser = contentType.xContent().createParser(parserConfig, originalSource.streamInput()); | ||
| builder.copyCurrentStructure(parser); | ||
| return BytesReference.bytes(builder); | ||
| }; |
There was a problem hiding this comment.
Compressed source not decompressed before parsing in filter
High Severity
The parser-based filtering branch detects content type using xContentTypeMayCompressed() which handles compressed bytes, but then passes originalSource.streamInput() directly to the parser without decompressing. If the source is compressed, the parser receives compressed bytes and will fail or produce incorrect results. The map-based branch correctly handles compression via XContentHelper.convertToMap. This is a regression since the old code in ShardGetService always used convertToMap which handles compression properly.


PR_013
Note
Medium Risk
Touches
_sourcefiltering during indexing and get responses, so mistakes could change returned/stored source fields; logic is localized but affects a core data path and adds content-type auto-detection for compressed inputs.Overview
Adds
XContentFieldFilter, a reusable field-filtering abstraction for_sourcebytes that chooses between map-based filtering (when exclude wildcards are present) and streaming parser-based filtering otherwise, including content-type detection when needed.Refactors
SourceFieldMapperandShardGetServiceto use this new filter for include/exclude source filtering, replacing manualconvertToMap+XContentMapValues.filterrebuild logic.Introduces deprecated helper
XContentHelper.xContentTypeMayCompressedto detect content type on possibly-compressed bytes for the new streaming filter path.Written by Cursor Bugbot for commit 4560a0c. This will update automatically on new commits. Configure here.