diff --git a/docs/changelog/143733.yaml b/docs/changelog/143733.yaml new file mode 100644 index 0000000000000..8aa6b979f80ee --- /dev/null +++ b/docs/changelog/143733.yaml @@ -0,0 +1,6 @@ +area: Search +issues: + - 143732 +pr: 143733 +summary: Fix nested object float arrays being mapped to dense vectors when they are mapped in dynamic template mappings +type: enhancement diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/60_dense_vector_dynamic_mapping.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/60_dense_vector_dynamic_mapping.yml index 567d338da142c..de802618f1913 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/60_dense_vector_dynamic_mapping.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/60_dense_vector_dynamic_mapping.yml @@ -319,6 +319,7 @@ setup: my_dynamic_field: [ 159.1, 289.56, -128.7424, 145.9871, -164.0003, 86.4034, -89.6929, 257.9717, 131.6075, 67.9233, -144.8255, 223.8446, 77.3228, -210.1163, -139.4783, 12.6499, 15.4491, 108.3465, -189.3947, 178.2045, -187.5925, 184.5089, 77.3022, -202.7439, -13.4959, 115.9719, -139.4332, 196.7845, 104.7573, -156.7746, 166.9878, 68.3936, 159.8473, -141.4446, 21.1947, 186.5908, -209.6895, 68.6169, 44.1255, 147.4659, 56.5079, -179.7997, -85.1651, 11.4847, 124.1662, 96.2246, -178.6705, 85.5925, 205.3616, -16.4704, 172.4947, -115.2535, -58.1722, 94.4836, 34.6458, -70.1011, -58.8047, 149.9562, -37.8998, 196.9805, -169.3555, -163.9432, 188.5611, 214.8378, 29.3182, -24.8724, 152.9382, -109.4345, -123.6716, -8.2441, 64.5902, 27.8083, 40.8185, -94.3161, 58.1463, -138.7432, 24.6805, -88.7222, -11.2018, 206.6434, 201.9024, 87.3079, -3.2883, -60.2484, -109.5789, 105.5766, -116.6709, -17.7073, -71.5093, -75.2937, -176.8691, -146.4967, 53.7586, 199.5294, 55.9754, -48.7399, 82.2051, 135.2921, 22.4408, -116.4008, -33.7538, 29.7207, 6.3692, -97.5768, -12.7982, -200.9331, -62.2743, 81.0843, 136.2247, 150.2565, 139.6838, 155.2657, -25.7447, 198.5955, 18.8099, 46.9014, -60.2672, 136.4801, 171.8966, 172.5842, 13.9123, 75.8386, -64.2444, -48.1964, 135.9685, 7.4927, -40.6424, -76.8922 ] + - do: cluster.health: wait_for_events: languid @@ -338,6 +339,45 @@ setup: - match: { my-dynamic-template-index.mappings.properties.my_dynamic_field.index: true } - match: { my-dynamic-template-index.mappings.properties.my_dynamic_field.similarity: cosine } +--- +"Float arrays inside nested objects respect float dynamic templates and are not mapped as dense_vector": + + - requires: + cluster_features: "mapper.dense_vector.dynamic_template_nested_object_fix" + reason: 'Fix for dynamic template not being applied to float arrays inside nested objects was added in 9.4' + + - do: + indices.create: + index: my-nested-dynamic-template-index + body: + mappings: + dynamic_templates: + - my_float_template: + match: "*float*" + mapping: + type: float + + - do: + index: + index: my-nested-dynamic-template-index + id: "1" + refresh: true + body: + my_object: + my_float_field: [ + 159.1, 289.56, -128.7424, 145.9871, -164.0003, 86.4034, -89.6929, 257.9717, 131.6075, 67.9233, -144.8255, 223.8446, 77.3228, -210.1163, -139.4783, 12.6499, 15.4491, 108.3465, -189.3947, 178.2045, -187.5925, 184.5089, 77.3022, -202.7439, -13.4959, 115.9719, -139.4332, 196.7845, 104.7573, -156.7746, 166.9878, 68.3936, 159.8473, -141.4446, 21.1947, 186.5908, -209.6895, 68.6169, 44.1255, 147.4659, 56.5079, -179.7997, -85.1651, 11.4847, 124.1662, 96.2246, -178.6705, 85.5925, 205.3616, -16.4704, 172.4947, -115.2535, -58.1722, 94.4836, 34.6458, -70.1011, -58.8047, 149.9562, -37.8998, 196.9805, -169.3555, -163.9432, 188.5611, 214.8378, 29.3182, -24.8724, 152.9382, -109.4345, -123.6716, -8.2441, 64.5902, 27.8083, 40.8185, -94.3161, 58.1463, -138.7432, 24.6805, -88.7222, -11.2018, 206.6434, 201.9024, 87.3079, -3.2883, -60.2484, -109.5789, 105.5766, -116.6709, -17.7073, -71.5093, -75.2937, -176.8691, -146.4967, 53.7586, 199.5294, 55.9754, -48.7399, 82.2051, 135.2921, 22.4408, -116.4008, -33.7538, 29.7207, 6.3692, -97.5768, -12.7982, -200.9331, -62.2743, 81.0843, 136.2247, 150.2565, 139.6838, 155.2657, -25.7447, 198.5955, 18.8099, 46.9014, -60.2672, 136.4801, 171.8966, 172.5842, 13.9123, 75.8386, -64.2444, -48.1964, 135.9685, 7.4927, -40.6424, -76.8922 + ] + + - do: + cluster.health: + wait_for_events: languid + + - do: + indices.get_mapping: + index: my-nested-dynamic-template-index + + - match: { my-nested-dynamic-template-index.mappings.properties.my_object.properties.my_float_field.type: float } + --- "Fields mapped as dense_vector without dims dynamically map the dim size to the first indexed document": diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java b/server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java index 012a352a3f499..0fd823243aa34 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DynamicFieldsBuilder.java @@ -210,7 +210,8 @@ private static boolean createDynamicField( CheckedSupplier dynamicFieldStrategy ) throws IOException { if (applyMatchingTemplate(context, name, matchType, dateFormatter)) { - context.markFieldAsAppliedFromTemplate(name); + String fullFieldName = context.path().pathAsText(name); + context.markFieldAsAppliedFromTemplate(fullFieldName); return true; } else { return dynamicFieldStrategy.get(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java index 97d76e4fbaf99..a85b18358eb43 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java @@ -55,6 +55,9 @@ public class MapperFeatures implements FeatureSpecification { static final NodeFeature EXCLUDE_VECTORS_DOCVALUE_BUGFIX = new NodeFeature("mapper.exclude_vectors_docvalue_bugfix"); public static final NodeFeature FIX_DENSE_VECTOR_WRONG_FIELDS = new NodeFeature("mapper.fix_dense_vector_wrong_fields"); static final NodeFeature STORED_FIELDS_SPEC_MERGE_BUG = new NodeFeature("mapper.stored_fields_spec_merge_bug"); + static final NodeFeature DENSE_VECTOR_DYNAMIC_TEMPLATE_NESTED_OBJECT_FIX = new NodeFeature( + "mapper.dense_vector.dynamic_template_nested_object_fix" + ); @Override public Set getTestFeatures() { @@ -95,7 +98,8 @@ public Set getTestFeatures() { PATTERN_TEXT_RENAME, EXCLUDE_VECTORS_DOCVALUE_BUGFIX, FIX_DENSE_VECTOR_WRONG_FIELDS, - STORED_FIELDS_SPEC_MERGE_BUG + STORED_FIELDS_SPEC_MERGE_BUG, + DENSE_VECTOR_DYNAMIC_TEMPLATE_NESTED_OBJECT_FIX ); } }