mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-01 09:42:11 +00:00
Add Map to ElasticsearchSimpleTypes.
See #1675. (cherry picked from commit 27850e96f211b093a82f2e8a69d13bdc3364d50c)
This commit is contained in:
parent
d811ff2d78
commit
8fa261360f
@ -277,28 +277,26 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
routingResolver);
|
routingResolver);
|
||||||
adaptibleEntity.populateIdIfNecessary(indexedObjectInformation.getId());
|
adaptibleEntity.populateIdIfNecessary(indexedObjectInformation.getId());
|
||||||
|
|
||||||
ElasticsearchPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(entity.getClass());
|
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||||
PersistentPropertyAccessor<Object> propertyAccessor = persistentEntity.getPropertyAccessor(entity);
|
if (persistentEntity != null) {
|
||||||
|
PersistentPropertyAccessor<Object> propertyAccessor = persistentEntity.getPropertyAccessor(entity);
|
||||||
|
|
||||||
if (indexedObjectInformation.getSeqNo() != null && indexedObjectInformation.getPrimaryTerm() != null
|
if (indexedObjectInformation.getSeqNo() != null && indexedObjectInformation.getPrimaryTerm() != null
|
||||||
&& persistentEntity.hasSeqNoPrimaryTermProperty()) {
|
&& persistentEntity.hasSeqNoPrimaryTermProperty()) {
|
||||||
ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity.getSeqNoPrimaryTermProperty();
|
ElasticsearchPersistentProperty seqNoPrimaryTermProperty = persistentEntity.getSeqNoPrimaryTermProperty();
|
||||||
propertyAccessor.setProperty(seqNoPrimaryTermProperty,
|
propertyAccessor.setProperty(seqNoPrimaryTermProperty,
|
||||||
new SeqNoPrimaryTerm(indexedObjectInformation.getSeqNo(), indexedObjectInformation.getPrimaryTerm()));
|
new SeqNoPrimaryTerm(indexedObjectInformation.getSeqNo(), indexedObjectInformation.getPrimaryTerm()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexedObjectInformation.getVersion() != null && persistentEntity.hasVersionProperty()) {
|
if (indexedObjectInformation.getVersion() != null && persistentEntity.hasVersionProperty()) {
|
||||||
ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty();
|
ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty();
|
||||||
propertyAccessor.setProperty(versionProperty, indexedObjectInformation.getVersion());
|
propertyAccessor.setProperty(versionProperty, indexedObjectInformation.getVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ElasticsearchPersistentEntity<?> getRequiredPersistentEntity(Class<?> clazz) {
|
|
||||||
return converter.getMappingContext().getRequiredPersistentEntity(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Flux<T> multiGet(Query query, Class<T> clazz) {
|
public <T> Flux<T> multiGet(Query query, Class<T> clazz) {
|
||||||
return multiGet(query, clazz, getIndexCoordinatesFor(clazz));
|
return multiGet(query, clazz, getIndexCoordinatesFor(clazz));
|
||||||
|
@ -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.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.*;
|
import org.springframework.data.elasticsearch.core.query.*;
|
||||||
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -1730,12 +1731,18 @@ class RequestFactory {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private String getPersistentEntityId(Object entity) {
|
private String getPersistentEntityId(Object entity) {
|
||||||
|
|
||||||
Object identifier = elasticsearchConverter.getMappingContext() //
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = elasticsearchConverter
|
||||||
.getRequiredPersistentEntity(entity.getClass()) //
|
.getMappingContext();
|
||||||
.getIdentifierAccessor(entity).getIdentifier();
|
|
||||||
|
|
||||||
if (identifier != null) {
|
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entity.getClass());
|
||||||
return identifier.toString();
|
|
||||||
|
if (persistentEntity != null) {
|
||||||
|
Object identifier = persistentEntity //
|
||||||
|
.getIdentifierAccessor(entity).getIdentifier();
|
||||||
|
|
||||||
|
if (identifier != null) {
|
||||||
|
return identifier.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -1743,8 +1750,16 @@ class RequestFactory {
|
|||||||
|
|
||||||
private VersionType retrieveVersionTypeFromPersistentEntity(Class<?> clazz) {
|
private VersionType retrieveVersionTypeFromPersistentEntity(Class<?> clazz) {
|
||||||
|
|
||||||
VersionType versionType = elasticsearchConverter.getMappingContext().getRequiredPersistentEntity(clazz)
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = elasticsearchConverter
|
||||||
.getVersionType();
|
.getMappingContext();
|
||||||
|
|
||||||
|
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
|
||||||
|
|
||||||
|
VersionType versionType = null;
|
||||||
|
|
||||||
|
if (persistentEntity != null) {
|
||||||
|
versionType = persistentEntity.getVersionType();
|
||||||
|
}
|
||||||
|
|
||||||
return versionType != null ? versionType : VersionType.EXTERNAL;
|
return versionType != null ? versionType : VersionType.EXTERNAL;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.core.mapping;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.document.Document;
|
import org.springframework.data.elasticsearch.core.document.Document;
|
||||||
@ -40,6 +41,8 @@ public class ElasticsearchSimpleTypes {
|
|||||||
|
|
||||||
Set<Class<?>> simpleTypes = new HashSet<>();
|
Set<Class<?>> simpleTypes = new HashSet<>();
|
||||||
simpleTypes.add(Document.class);
|
simpleTypes.add(Document.class);
|
||||||
|
simpleTypes.add(Map.class);
|
||||||
|
|
||||||
ELASTICSEARCH_SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
|
ELASTICSEARCH_SIMPLE_TYPES = Collections.unmodifiableSet(simpleTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user