Skip to content

Add excludeFromSource handling to multifield #2975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ private void buildPropertyMapping(ObjectNode propertiesNode, boolean isRootObjec
: 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);
}

Expand Down Expand Up @@ -381,17 +383,15 @@ private void buildPropertyMapping(ObjectNode propertiesNode, boolean isRootObjec
}
}

MultiField multiField = property.findAnnotation(MultiField.class);

if (isCompletionProperty) {
CompletionField completionField = property.findAnnotation(CompletionField.class);
applyCompletionFieldMapping(propertiesNode, property, completionField);
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,38 +1126,49 @@ void shouldAddFieldsThatAreExcludedFromSource() throws JSONException {

String expected = """
{
"properties": {
"_class": {
"type": "keyword",
"index": false,
"doc_values": false
},
"excluded-date": {
"type": "date",
"format": "date"
},
"nestedEntity": {
"type": "nested",
"properties": {
"_class": {
"type": "keyword",
"index": false,
"doc_values": false
},
"excluded-text": {
"type": "text"
}
}
}
},
"_source": {
"excludes": [
"excluded-date",
"nestedEntity.excluded-text"
]
}
}
"""; //
"properties": {
"_class": {
"type": "keyword",
"index": false,
"doc_values": false
},
"excluded-date": {
"type": "date",
"format": "date"
},
"nestedEntity": {
"type": "nested",
"properties": {
"_class": {
"type": "keyword",
"index": false,
"doc_values": false
},
"excluded-text": {
"type": "text"
}
}
},
"excluded-multifield": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
},
"_source": {
"excludes": [
"excluded-date",
"nestedEntity.excluded-text",
"excluded-multifield"
]
}

}

"""; //

String mapping = getMappingBuilder().buildPropertyMapping(ExcludedFieldEntity.class);

Expand Down Expand Up @@ -1243,7 +1254,7 @@ void shouldWriteFieldAliasesToTheMapping() throws JSONException {

assertEquals(expected, mapping, true);
}

@Test // #2942
@DisplayName("should use custom mapped name")
void shouldUseCustomMappedName() throws JSONException {
Expand Down Expand Up @@ -2192,8 +2203,7 @@ static class DenseVectorEntityWithKnnSearch {
@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() {
Expand Down Expand Up @@ -2269,8 +2279,7 @@ public void setText(@Nullable String text) {
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 {
Expand Down Expand Up @@ -2553,6 +2562,10 @@ private static class ExcludedFieldEntity {
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")
Expand Down Expand Up @@ -2599,8 +2612,10 @@ private static class FieldMappedNameEntity {
@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")
Expand Down