Add Map to ElasticsearchSimpleTypes.

See #1675.

(cherry picked from commit 27850e96f211b093a82f2e8a69d13bdc3364d50c)
This commit is contained in:
Mark Paluch 2021-02-02 10:27:45 +01:00 committed by Peter-Josef Meisch
parent d811ff2d78
commit 8fa261360f
No known key found for this signature in database
GPG Key ID: DE108246970C7708
3 changed files with 38 additions and 22 deletions

View File

@ -277,28 +277,26 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
routingResolver);
adaptibleEntity.populateIdIfNecessary(indexedObjectInformation.getId());
ElasticsearchPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(entity.getClass());
PersistentPropertyAccessor<Object> propertyAccessor = persistentEntity.getPropertyAccessor(entity);
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
if (persistentEntity != null) {
PersistentPropertyAccessor<Object> propertyAccessor = persistentEntity.getPropertyAccessor(entity);
if (indexedObjectInformation.getSeqNo() != null && indexedObjectInformation.getPrimaryTerm() != null
&& persistentEntity.hasSeqNoPrimaryTermProperty()) {
ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity.getSeqNoPrimaryTermProperty();
propertyAccessor.setProperty(seqNoPrimaryTermProperty,
new SeqNoPrimaryTerm(indexedObjectInformation.getSeqNo(), indexedObjectInformation.getPrimaryTerm()));
}
if (indexedObjectInformation.getSeqNo() != null && indexedObjectInformation.getPrimaryTerm() != null
&& persistentEntity.hasSeqNoPrimaryTermProperty()) {
ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity.getSeqNoPrimaryTermProperty();
propertyAccessor.setProperty(seqNoPrimaryTermProperty,
new SeqNoPrimaryTerm(indexedObjectInformation.getSeqNo(), indexedObjectInformation.getPrimaryTerm()));
}
if (indexedObjectInformation.getVersion() != null && persistentEntity.hasVersionProperty()) {
ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty();
propertyAccessor.setProperty(versionProperty, indexedObjectInformation.getVersion());
if (indexedObjectInformation.getVersion() != null && persistentEntity.hasVersionProperty()) {
ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty();
propertyAccessor.setProperty(versionProperty, indexedObjectInformation.getVersion());
}
}
return entity;
}
private ElasticsearchPersistentEntity<?> getRequiredPersistentEntity(Class<?> clazz) {
return converter.getMappingContext().getRequiredPersistentEntity(clazz);
}
@Override
public <T> Flux<T> multiGet(Query query, Class<T> clazz) {
return multiGet(query, clazz, getIndexCoordinatesFor(clazz));

View File

@ -107,6 +107,7 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.*;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@ -1730,12 +1731,18 @@ class RequestFactory {
@Nullable
private String getPersistentEntityId(Object entity) {
Object identifier = elasticsearchConverter.getMappingContext() //
.getRequiredPersistentEntity(entity.getClass()) //
.getIdentifierAccessor(entity).getIdentifier();
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = elasticsearchConverter
.getMappingContext();
if (identifier != null) {
return identifier.toString();
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entity.getClass());
if (persistentEntity != null) {
Object identifier = persistentEntity //
.getIdentifierAccessor(entity).getIdentifier();
if (identifier != null) {
return identifier.toString();
}
}
return null;
@ -1743,8 +1750,16 @@ class RequestFactory {
private VersionType retrieveVersionTypeFromPersistentEntity(Class<?> clazz) {
VersionType versionType = elasticsearchConverter.getMappingContext().getRequiredPersistentEntity(clazz)
.getVersionType();
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = elasticsearchConverter
.getMappingContext();
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
VersionType versionType = null;
if (persistentEntity != null) {
versionType = persistentEntity.getVersionType();
}
return versionType != null ? versionType : VersionType.EXTERNAL;
}

View File

@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.core.mapping;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.springframework.data.elasticsearch.core.document.Document;
@ -40,6 +41,8 @@ public class ElasticsearchSimpleTypes {
Set<Class<?>> simpleTypes = new HashSet<>();
simpleTypes.add(Document.class);
simpleTypes.add(Map.class);
ELASTICSEARCH_SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
}