mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 12:02:10 +00:00
Add excludeFromSource handling to multifield.
Original Pull Request #2975 Closes #2971
This commit is contained in:
parent
81eb167981
commit
555b570246
@ -349,8 +349,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,8 +383,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);
|
||||||
@ -390,8 +390,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);
|
||||||
}
|
}
|
||||||
|
@ -1126,38 +1126,49 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
|
|||||||
|
|
||||||
String expected = """
|
String expected = """
|
||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
"_class": {
|
"_class": {
|
||||||
"type": "keyword",
|
"type": "keyword",
|
||||||
"index": false,
|
"index": false,
|
||||||
"doc_values": false
|
"doc_values": false
|
||||||
},
|
},
|
||||||
"excluded-date": {
|
"excluded-date": {
|
||||||
"type": "date",
|
"type": "date",
|
||||||
"format": "date"
|
"format": "date"
|
||||||
},
|
},
|
||||||
"nestedEntity": {
|
"nestedEntity": {
|
||||||
"type": "nested",
|
"type": "nested",
|
||||||
"properties": {
|
"properties": {
|
||||||
"_class": {
|
"_class": {
|
||||||
"type": "keyword",
|
"type": "keyword",
|
||||||
"index": false,
|
"index": false,
|
||||||
"doc_values": false
|
"doc_values": false
|
||||||
},
|
},
|
||||||
"excluded-text": {
|
"excluded-text": {
|
||||||
"type": "text"
|
"type": "text"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
"excluded-multifield": {
|
||||||
"_source": {
|
"type": "text",
|
||||||
"excludes": [
|
"fields": {
|
||||||
"excluded-date",
|
"keyword": {
|
||||||
"nestedEntity.excluded-text"
|
"type": "keyword"
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""; //
|
},
|
||||||
|
"_source": {
|
||||||
|
"excludes": [
|
||||||
|
"excluded-date",
|
||||||
|
"nestedEntity.excluded-text",
|
||||||
|
"excluded-multifield"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
"""; //
|
||||||
|
|
||||||
String mapping = getMappingBuilder().buildPropertyMapping(ExcludedFieldEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(ExcludedFieldEntity.class);
|
||||||
|
|
||||||
@ -2192,8 +2203,7 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Field(type = FieldType.Dense_Vector, dims = 16, elementType = FieldElementType.FLOAT,
|
@Field(type = FieldType.Dense_Vector, dims = 16, elementType = FieldElementType.FLOAT,
|
||||||
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100),
|
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100),
|
||||||
knnSimilarity = KnnSimilarity.DOT_PRODUCT)
|
knnSimilarity = KnnSimilarity.DOT_PRODUCT) private float[] my_vector;
|
||||||
private float[] my_vector;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@ -2269,8 +2279,7 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
|
|||||||
static class DenseVectorMisMatchConfidenceIntervalClass {
|
static class DenseVectorMisMatchConfidenceIntervalClass {
|
||||||
@Field(type = Dense_Vector, dims = 16, elementType = FieldElementType.FLOAT,
|
@Field(type = Dense_Vector, dims = 16, elementType = FieldElementType.FLOAT,
|
||||||
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, confidenceInterval = 0.95F),
|
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, confidenceInterval = 0.95F),
|
||||||
knnSimilarity = KnnSimilarity.DOT_PRODUCT)
|
knnSimilarity = KnnSimilarity.DOT_PRODUCT) private float[] dense_vector;
|
||||||
private float[] dense_vector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class DisabledMappingProperty {
|
static class DisabledMappingProperty {
|
||||||
@ -2553,6 +2562,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")
|
||||||
@ -2599,8 +2612,10 @@ public class MappingBuilderUnitTests extends MappingContextBaseTests {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class MultiFieldMappedNameEntity {
|
private static class MultiFieldMappedNameEntity {
|
||||||
@Nullable
|
@Nullable
|
||||||
@MultiField(mainField = @Field(type = FieldType.Text, mappedTypeName = "match_only_text"), otherFields = { @InnerField(suffix = "lower_case",
|
@MultiField(mainField = @Field(type = FieldType.Text, mappedTypeName = "match_only_text"),
|
||||||
type = FieldType.Keyword, normalizer = "lower_case_normalizer", mappedTypeName = "constant_keyword") }) private String description;
|
otherFields = { @InnerField(suffix = "lower_case",
|
||||||
|
type = FieldType.Keyword, normalizer = "lower_case_normalizer",
|
||||||
|
mappedTypeName = "constant_keyword") }) private String description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user