Skip to content

[9.1] fix: dynamic template vector array is overridden by automatic dense_vector mapping (#143733)#145698

Closed
salvatore-campagna wants to merge 1 commit intoelastic:9.1from
salvatore-campagna:backport/9.1/pr-143733
Closed

[9.1] fix: dynamic template vector array is overridden by automatic dense_vector mapping (#143733)#145698
salvatore-campagna wants to merge 1 commit intoelastic:9.1from
salvatore-campagna:backport/9.1/pr-143733

Conversation

@salvatore-campagna
Copy link
Copy Markdown
Contributor

Backport Note

This is a backport of #143733 to 9.1, identical to the 8.19 backport in #143985.

This backport is needed because the rest-compatibility CI check (yamlRestCompatTest) on the 9.1 branch fails for any PR due to the missing fix. Specifically, the test search.vectors/60_dense_vector_dynamic_mapping/Float arrays inside nested objects respect float dynamic templates and are not mapped as dense_vector was added upstream but the underlying bug fix was never backported to 9.1, causing a rest-compatibility CI failure (e.g., see #144765).


Problem

When a float array is inside a nested object (e.g., my_object.my_float_field) and a dynamic template matches that field name (e.g., match: "*float*" with type: float), the dynamic template is not respected. Instead, the array is automatically mapped as dense_vector.

The root cause is in DynamicFieldsBuilder.createDynamicField(): markFieldAsAppliedFromTemplate(name) uses the short field name (my_float_field), but the automatic dense_vector mapping check uses the full path (my_object.my_float_field). Since they don't match, the "applied from template" marker is missed and the array gets auto-mapped as dense_vector.

Fix

Use context.path().pathAsText(name) instead of name when calling markFieldAsAppliedFromTemplate, so the full field path is stored and correctly matched during the dense_vector auto-detection check.

Tests

  • YAML REST test: Float arrays inside nested objects respect float dynamic templates and are not mapped as dense_vector gated behind the mapper.dense_vector.dynamic_template_nested_object_fix cluster feature.
./gradlew :rest-api-spec:yamlRestTest --tests "*60_dense_vector_dynamic_mapping*Float arrays inside nested*"

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants