Add mappings for enrich fields (#96056)#10
Add mappings for enrich fields (#96056)#10MitchLewis930 wants to merge 1 commit intopr_020_beforefrom
Conversation
We are developing a new component that performs lookup during query time. The idea is to utilize the existing enrich policies and indices used during indexing. However, to ensure proper functionality of the new component, we need the mapping types and doc_values of the enrich fields. With this change, populating the mapping for enrich fields is a best-effort process to maintain the current behavior. This means that any mapping conflicts arising between the enrich fields of the source indices will be ignored. I will follow up to address this validation issue.
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.
| if (strictlyRequired) { | ||
| throw new ElasticsearchException( | ||
| "Multiple distinct formats specified for field '{}' - indices({}) format entries({})", | ||
| policy.getMatchField(), |
There was a problem hiding this comment.
Wrong field name used in format error message
Low Severity
The error message for multiple distinct formats uses policy.getMatchField() instead of fieldName. The method takes fieldName as a parameter and correctly uses it in the similar error for multiple types at line 217. Using the wrong variable causes the exception message to report an incorrect field name when a non-match field has conflicting formats.
| } | ||
| if (formatEntries.isEmpty()) { | ||
| // no format specify rely on default | ||
| return createEnrichMappingBuilder((builder) -> builder.field("type", type).field("doc_values", false)); |
There was a problem hiding this comment.
Unreachable null check is dead code
Low Severity
The if (currentField == null) check at line 300 is dead code. The for loop above (lines 257-299) is guaranteed to execute at least once since fieldName is asserted non-empty at line 252. Inside the loop, if currentField becomes null (line 280), the method either throws an exception or returns null (lines 281-291). Therefore, after the loop completes normally, currentField is always non-null, making this check unreachable.


PR_020
Note
Medium Risk
Changes how enrich index mappings are generated/validated and can alter field capabilities (indexing/doc_values) for downstream enrich lookups. Risk is moderated by extensive test updates and added conflict-coverage, but it touches core ingest/enrich behavior.
Overview
Enrich policy execution now creates enrich indices with explicit mappings for all configured
enrich_fields, not just the match field. Non-match enrich fields are copied from source mappings (includingformatwhere applicable), markedindex: false, and the match field mapping logic is refactored to validate consistent types/formats across all source indices (preserving range/date_range formats and enabling doc values when the match field is also an enrich field).Tests are updated to assert the expanded mappings and add coverage for cross-index conflicts where enrich fields have incompatible types or formats (these fields are omitted from the enrich index mapping rather than failing policy execution unless the conflict is on the required match field).
Written by Cursor Bugbot for commit 00afc5b. This will update automatically on new commits. Configure here.