DATAES-936 - Take id property from the source when deserializing an entity.

Original PR: #523
This commit is contained in:
Peter-Josef Meisch 2020-09-23 20:05:43 +02:00 committed by GitHub
parent 54909a83cb
commit 8d4c305732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -860,13 +860,21 @@ public class MappingElasticsearchConverter
@Nullable
public Object get(ElasticsearchPersistentProperty property) {
String fieldName = property.getFieldName();
if (target instanceof Document) {
// nested objects may have properties like 'id' which are recognized as isIdProperty() but they are not
// Documents
Document document = (Document) target;
if (property.isIdProperty() && document.hasId()) {
return document.getId();
Object id = null;
// take the id property from the document source if available
if (!fieldName.contains(".")) {
id = target.get(fieldName);
}
return id != null ? id : document.getId();
}
if (property.isVersionProperty() && document.hasVersion()) {
@ -879,8 +887,6 @@ public class MappingElasticsearchConverter
return ((SearchDocument) target).getScore();
}
String fieldName = property.getFieldName();
if (!fieldName.contains(".")) {
return target.get(fieldName);
}