Skip to content

Comments

Add mappings for enrich fields (#96056)#10

Open
MitchLewis930 wants to merge 1 commit intopr_020_beforefrom
pr_020_after
Open

Add mappings for enrich fields (#96056)#10
MitchLewis930 wants to merge 1 commit intopr_020_beforefrom
pr_020_after

Conversation

@MitchLewis930
Copy link

PR_020

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.
@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 00:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the enrich policy functionality by adding field mappings for all enrich fields, not just the match field. Previously, only the match field had its mapping preserved in the enrich index, while other enrich fields were unmapped. This change ensures that all enrich fields retain their mapping types and settings from the source indices.

Changes:

  • Refactored mapping validation and creation logic to handle all enrich fields
  • Added validation for mapping conflicts across multiple source indices
  • Updated test assertions to verify mappings for all fields, not just the match field

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java Refactored mapping resolution to create mappings for all enrich fields with conflict detection across source indices
x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunnerTests.java Updated all test cases to verify complete field mappings and added new tests for mapping conflict scenarios
docs/changelog/96056.yaml Added changelog entry documenting the enhancement

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +232 to +239
policy.getMatchField(),
Strings.collectionToCommaDelimitedString(policy.getIndices()),
Strings.collectionToCommaDelimitedString(formats)
);
}
return null;
}
return new MappingTypeAndFormat(Iterables.get(types, 0), formats.isEmpty() ? null : Iterables.get(formats, 0));
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message references policy.getMatchField() but should reference the fieldName parameter since this validation is used for both match fields and enrich fields. The error message will be incorrect when validating enrich fields with format conflicts.

Suggested change
policy.getMatchField(),
Strings.collectionToCommaDelimitedString(policy.getIndices()),
Strings.collectionToCommaDelimitedString(formats)
);
}
return null;
}
return new MappingTypeAndFormat(Iterables.get(types, 0), formats.isEmpty() ? null : Iterables.get(formats, 0));
fieldName,
Strings.collectionToCommaDelimitedString(policy.getIndices()),
Strings.collectionToCommaDelimitedString(formats)
);
}
return null;
}
return new MappingTypeAndFormat(Iterables.get(types, 0), formats.isEmpty() ? null : Iteriles.get(formats, 0));

Copilot uses AI. Check for mistakes.
Comment on lines +243 to +246
private static <T> T extractValues(Map<String, Object> properties, String path) {
return (T) properties.get(path);
}

Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name extractValues is misleading as it extracts a single value, not multiple values. Consider renaming to extractValue or getProperty to better reflect that it retrieves a single property value from the map.

Suggested change
private static <T> T extractValues(Map<String, Object> properties, String path) {
return (T) properties.get(path);
}
private static <T> T extractValue(Map<String, Object> properties, String path) {
return (T) properties.get(path);
}
/**
* @deprecated Use {@link #extractValue(Map, String)} instead.
*/
@Deprecated
@SuppressWarnings("unchecked")
private static <T> T extractValues(Map<String, Object> properties, String path) {
return extractValue(properties, path);
}

Copilot uses AI. Check for mistakes.
@@ -194,11 +195,64 @@ static void validateMappings(
}
}

Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MappingTypeAndFormat record lacks documentation explaining its purpose and the meaning of its parameters. Add a JavaDoc comment describing that it encapsulates field mapping type and optional format information extracted from source index mappings.

Suggested change
/**
* Encapsulates the mapping type and optional format for a field as derived from
* the source index mappings used by an enrich policy.
*
* @param type the field mapping type (for example, {@code keyword}, {@code date}, etc.)
* @param format the optional mapping format string for the field (for example, a date format),
* or {@code null} if the field does not define a format
*/

Copilot uses AI. Check for mistakes.
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.

2 participants