diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java index 9846e8f6c..9b47ce583 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java @@ -197,37 +197,35 @@ public class MappingBuilder { } } - boolean isGeoPointProperty = isGeoPointProperty(property); + if (isGeoPointProperty(property)) { + applyGeoPointFieldMapping(builder, property); + return; + } + + Field fieldAnnotation = property.findAnnotation(Field.class); boolean isCompletionProperty = isCompletionProperty(property); boolean isNestedOrObjectProperty = isNestedOrObjectProperty(property); - Field fieldAnnotation = property.findAnnotation(Field.class); - if (!isGeoPointProperty && !isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) { + if (!isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) { if (fieldAnnotation == null) { return; } - Iterator> iterator = property.getPersistentEntityTypes().iterator(); - ElasticsearchPersistentEntity persistentEntity = iterator.hasNext() - ? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next()) - : null; - - mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty, - fieldAnnotation.type(), fieldAnnotation, property.findAnnotation(DynamicMapping.class)); - if (isNestedOrObjectProperty) { + Iterator> iterator = property.getPersistentEntityTypes().iterator(); + ElasticsearchPersistentEntity persistentEntity = iterator.hasNext() + ? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next()) + : null; + + mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty, + fieldAnnotation.type(), fieldAnnotation, property.findAnnotation(DynamicMapping.class)); return; } } MultiField multiField = property.findAnnotation(MultiField.class); - if (isGeoPointProperty) { - applyGeoPointFieldMapping(builder, property); - return; - } - if (isCompletionProperty) { CompletionField completionField = property.findAnnotation(CompletionField.class); applyCompletionFieldMapping(builder, property, completionField); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java index 2427311f7..eb1de495c 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java @@ -545,6 +545,21 @@ public class MappingBuilderTests extends MappingContextBaseTests { assertEquals(expected, mapping, true); } + @Test // DATAES-784 + void shouldMapPropertyObjectsToFieldDefinition() throws JSONException { + String expected = "{\n" + // + " properties: {\n" + // + " valueObject: {\n" + // + " type: \"text\"\n" + // + " }\n" + // + " }\n" + // + "}"; + + String mapping = getMappingBuilder().buildPropertyMapping(ValueDoc.class); + + assertEquals(expected, mapping, true); + } + /** * @author Xiao Yu */ @@ -997,4 +1012,21 @@ public class MappingBuilderTests extends MappingContextBaseTests { this.author = author; } } + + static class ValueObject { + private String value; + + public ValueObject(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + @Document(indexName = "valueDoc") + static class ValueDoc { + @Field(type = Text) private ValueObject valueObject; + } }