mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-13 07:32:11 +00:00
DATAES-936 - Take id property from the source when deserializing an entity.
Original PR: #523 (cherry picked from commit 8d4c30573297f0481e09de5ab5e419dec775c769)
This commit is contained in:
parent
084dd1db56
commit
a88612df71
@ -830,13 +830,21 @@ public class MappingElasticsearchConverter
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Object get(ElasticsearchPersistentProperty property) {
|
public Object get(ElasticsearchPersistentProperty property) {
|
||||||
|
|
||||||
|
String fieldName = property.getFieldName();
|
||||||
|
|
||||||
if (target instanceof Document) {
|
if (target instanceof Document) {
|
||||||
// nested objects may have properties like 'id' which are recognized as isIdProperty() but they are not
|
// nested objects may have properties like 'id' which are recognized as isIdProperty() but they are not
|
||||||
// Documents
|
// Documents
|
||||||
Document document = (Document) target;
|
Document document = (Document) target;
|
||||||
|
|
||||||
if (property.isIdProperty() && document.hasId()) {
|
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()) {
|
if (property.isVersionProperty() && document.hasVersion()) {
|
||||||
@ -849,8 +857,6 @@ public class MappingElasticsearchConverter
|
|||||||
return ((SearchDocument) target).getScore();
|
return ((SearchDocument) target).getScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
String fieldName = property.getFieldName();
|
|
||||||
|
|
||||||
if (!fieldName.contains(".")) {
|
if (!fieldName.contains(".")) {
|
||||||
return target.get(fieldName);
|
return target.get(fieldName);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user