Add excludeFromSource handling to multifield.

Original Pull Request #2975
Closes #2971

(cherry picked from commit 555b5702467a904ecd40bac486d3ba4bdb71a744)
(cherry picked from commit a179dd06431ce7457d24c13902ba65477f7a92af)
This commit is contained in:
Peter-Josef Meisch 2024-08-31 21:18:35 +02:00
parent 74b05d21b5
commit 5a2dcd3b01
No known key found for this signature in database
GPG Key ID: DE108246970C7708
2 changed files with 52 additions and 37 deletions

View File

@ -334,8 +334,10 @@ public class MappingBuilder {
: nestedPropertyPrefix + '.' + property.getFieldName(); : nestedPropertyPrefix + '.' + property.getFieldName();
Field fieldAnnotation = property.findAnnotation(Field.class); 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); excludeFromSource.add(nestedPropertyPath);
} }
@ -366,8 +368,6 @@ public class MappingBuilder {
} }
} }
MultiField multiField = property.findAnnotation(MultiField.class);
if (isCompletionProperty) { if (isCompletionProperty) {
CompletionField completionField = property.findAnnotation(CompletionField.class); CompletionField completionField = property.findAnnotation(CompletionField.class);
applyCompletionFieldMapping(propertiesNode, property, completionField); applyCompletionFieldMapping(propertiesNode, property, completionField);
@ -375,8 +375,8 @@ public class MappingBuilder {
if (isRootObject && fieldAnnotation != null && property.isIdProperty()) { if (isRootObject && fieldAnnotation != null && property.isIdProperty()) {
applyDefaultIdFieldMapping(propertiesNode, property); applyDefaultIdFieldMapping(propertiesNode, property);
} else if (multiField != null) { } else if (multiFieldAnnotation != null) {
addMultiFieldMapping(propertiesNode, property, multiField, isNestedOrObjectProperty, dynamicMapping); addMultiFieldMapping(propertiesNode, property, multiFieldAnnotation, isNestedOrObjectProperty, dynamicMapping);
} else if (fieldAnnotation != null) { } else if (fieldAnnotation != null) {
addSingleFieldMapping(propertiesNode, property, fieldAnnotation, isNestedOrObjectProperty, dynamicMapping); addSingleFieldMapping(propertiesNode, property, fieldAnnotation, isNestedOrObjectProperty, dynamicMapping);
} }

View File

@ -1117,15 +1117,26 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
"type": "text" "type": "text"
} }
} }
},
"excluded-multifield": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
} }
}, },
"_source": { "_source": {
"excludes": [ "excludes": [
"excluded-date", "excluded-date",
"nestedEntity.excluded-text" "nestedEntity.excluded-text",
"excluded-multifield"
] ]
} }
} }
"""; // """; //
String mapping = getMappingBuilder().buildPropertyMapping(ExcludedFieldEntity.class); String mapping = getMappingBuilder().buildPropertyMapping(ExcludedFieldEntity.class);
@ -2367,6 +2378,10 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
excludeFromSource = true) private LocalDate excludedDate; excludeFromSource = true) private LocalDate excludedDate;
@Nullable @Nullable
@Field(type = Nested) private NestedExcludedFieldEntity nestedEntity; @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") @SuppressWarnings("unused")