Add excludeFromSource handling to multifield.

Original Pull Request #2975
Closes #2971
This commit is contained in:
Peter-Josef Meisch 2024-08-31 21:18:35 +02:00 committed by GitHub
parent 81eb167981
commit 555b570246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 44 deletions

View File

@ -349,8 +349,10 @@ public class MappingBuilder {
: nestedPropertyPrefix + '.' + property.getFieldName();
Field fieldAnnotation = property.findAnnotation(Field.class);
MultiField multiFieldAnnotation = property.findAnnotation(MultiField.class);
if (fieldAnnotation != null && fieldAnnotation.excludeFromSource()) {
if ((fieldAnnotation != null && fieldAnnotation.excludeFromSource()) ||
multiFieldAnnotation != null && multiFieldAnnotation.mainField().excludeFromSource()) {
excludeFromSource.add(nestedPropertyPath);
}
@ -381,8 +383,6 @@ public class MappingBuilder {
}
}
MultiField multiField = property.findAnnotation(MultiField.class);
if (isCompletionProperty) {
CompletionField completionField = property.findAnnotation(CompletionField.class);
applyCompletionFieldMapping(propertiesNode, property, completionField);
@ -390,8 +390,8 @@ public class MappingBuilder {
if (isRootObject && fieldAnnotation != null && property.isIdProperty()) {
applyDefaultIdFieldMapping(propertiesNode, property);
} else if (multiField != null) {
addMultiFieldMapping(propertiesNode, property, multiField, isNestedOrObjectProperty, dynamicMapping);
} else if (multiFieldAnnotation != null) {
addMultiFieldMapping(propertiesNode, property, multiFieldAnnotation, isNestedOrObjectProperty, dynamicMapping);
} else if (fieldAnnotation != null) {
addSingleFieldMapping(propertiesNode, property, fieldAnnotation, isNestedOrObjectProperty, dynamicMapping);
}

View File

@ -1148,15 +1148,26 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
"type": "text"
}
}
},
"excluded-multifield": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
},
"_source": {
"excludes": [
"excluded-date",
"nestedEntity.excluded-text"
"nestedEntity.excluded-text",
"excluded-multifield"
]
}
}
"""; //
String mapping = getMappingBuilder().buildPropertyMapping(ExcludedFieldEntity.class);
@ -2192,8 +2203,7 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
@Nullable
@Field(type = FieldType.Dense_Vector, dims = 16, elementType = FieldElementType.FLOAT,
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100),
knnSimilarity = KnnSimilarity.DOT_PRODUCT)
private float[] my_vector;
knnSimilarity = KnnSimilarity.DOT_PRODUCT) private float[] my_vector;
@Nullable
public String getId() {
@ -2269,8 +2279,7 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
static class DenseVectorMisMatchConfidenceIntervalClass {
@Field(type = Dense_Vector, dims = 16, elementType = FieldElementType.FLOAT,
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, confidenceInterval = 0.95F),
knnSimilarity = KnnSimilarity.DOT_PRODUCT)
private float[] dense_vector;
knnSimilarity = KnnSimilarity.DOT_PRODUCT) private float[] dense_vector;
}
static class DisabledMappingProperty {
@ -2553,6 +2562,10 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
excludeFromSource = true) private LocalDate excludedDate;
@Nullable
@Field(type = Nested) private NestedExcludedFieldEntity nestedEntity;
@Nullable
@MultiField(mainField = @Field(name = "excluded-multifield", type = Text, excludeFromSource = true), otherFields = {
@InnerField(suffix = "keyword", type = Keyword)
}) private String excludedMultifield;
}
@SuppressWarnings("unused")
@ -2599,8 +2612,10 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
@SuppressWarnings("unused")
private static class MultiFieldMappedNameEntity {
@Nullable
@MultiField(mainField = @Field(type = FieldType.Text, mappedTypeName = "match_only_text"), otherFields = { @InnerField(suffix = "lower_case",
type = FieldType.Keyword, normalizer = "lower_case_normalizer", mappedTypeName = "constant_keyword") }) private String description;
@MultiField(mainField = @Field(type = FieldType.Text, mappedTypeName = "match_only_text"),
otherFields = { @InnerField(suffix = "lower_case",
type = FieldType.Keyword, normalizer = "lower_case_normalizer",
mappedTypeName = "constant_keyword") }) private String description;
}
@SuppressWarnings("unused")