Skip to content

Commit 66b77ec

Browse files
sothawomp911de
authored andcommitted
DATAES-568 - MappingBuilder must use the @field annotation's name attribute.
Original pull request: #281.
1 parent e5c514e commit 66b77ec

13 files changed

+551
-277
lines changed

pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@
227227
</exclusions>
228228
</dependency>
229229

230+
<dependency>
231+
<groupId>org.skyscreamer</groupId>
232+
<artifactId>jsonassert</artifactId>
233+
<version>1.5.0</version>
234+
<scope>test</scope>
235+
</dependency>
236+
230237
<!-- Upgrade xbean to 4.5 to prevent incompatibilities due to ASM versions -->
231238
<dependency>
232239
<groupId>org.apache.xbean</groupId>

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import static org.elasticsearch.client.Requests.*;
1919
import static org.elasticsearch.index.query.QueryBuilders.*;
20-
import static org.springframework.data.elasticsearch.core.MappingBuilder.*;
2120
import static org.springframework.util.CollectionUtils.isEmpty;
2221
import static org.springframework.util.StringUtils.*;
2322

@@ -223,18 +222,12 @@ public <T> boolean putMapping(Class<T> clazz) {
223222
logger.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
224223
}
225224
}
226-
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
227-
XContentBuilder xContentBuilder = null;
228225
try {
229-
230-
ElasticsearchPersistentProperty property = persistentEntity.getRequiredIdProperty();
231-
232-
xContentBuilder = buildMapping(clazz, persistentEntity.getIndexType(), property.getFieldName(),
233-
persistentEntity.getParentType());
226+
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
227+
return putMapping(clazz, mappingBuilder.buildMapping(clazz));
234228
} catch (Exception e) {
235229
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
236230
}
237-
return putMapping(clazz, xContentBuilder);
238231
}
239232

240233
@Override

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import static org.elasticsearch.client.Requests.*;
1919
import static org.elasticsearch.index.query.QueryBuilders.*;
20-
import static org.springframework.data.elasticsearch.core.MappingBuilder.*;
2120
import static org.springframework.util.CollectionUtils.*;
2221

2322
import java.io.BufferedReader;
@@ -205,18 +204,12 @@ public <T> boolean putMapping(Class<T> clazz) {
205204
LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
206205
}
207206
}
208-
ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
209-
XContentBuilder xContentBuilder = null;
210207
try {
211-
212-
ElasticsearchPersistentProperty property = persistentEntity.getRequiredIdProperty();
213-
214-
xContentBuilder = buildMapping(clazz, persistentEntity.getIndexType(), property.getFieldName(),
215-
persistentEntity.getParentType());
208+
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
209+
return putMapping(clazz, mappingBuilder.buildMapping(clazz));
216210
} catch (Exception e) {
217211
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
218212
}
219-
return putMapping(clazz, xContentBuilder);
220213
}
221214

222215
@Override

0 commit comments

Comments
 (0)