mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-24 21:12:12 +00:00
DATAES-568 - Polishing.
Add package-info and nullability annotations to org.springframework.data.elasticsearch.core.mapping. Extract method to avoid excessive nesting. Add ticket references/convert old references to test methods. Move test models to inner classes. Use static imports for JSON Assert. Formatting. Original pull request: #281.
This commit is contained in:
parent
66b77ecb75
commit
b6fa4c8a74
@ -89,6 +89,7 @@ import org.elasticsearch.search.sort.SortOrder;
|
|||||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
@ -224,7 +225,7 @@ public class ElasticsearchRestTemplate
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
|
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
|
||||||
return putMapping(clazz, mappingBuilder.buildMapping(clazz));
|
return putMapping(clazz, mappingBuilder.buildPropertyMapping(clazz));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
|
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
|
||||||
}
|
}
|
||||||
@ -497,8 +498,7 @@ public class ElasticsearchRestTemplate
|
|||||||
@Override
|
@Override
|
||||||
public <T> CloseableIterator<T> stream(CriteriaQuery query, Class<T> clazz) {
|
public <T> CloseableIterator<T> stream(CriteriaQuery query, Class<T> clazz) {
|
||||||
final long scrollTimeInMillis = TimeValue.timeValueMinutes(1).millis();
|
final long scrollTimeInMillis = TimeValue.timeValueMinutes(1).millis();
|
||||||
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz), clazz,
|
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz), clazz, resultsMapper);
|
||||||
resultsMapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -509,8 +509,7 @@ public class ElasticsearchRestTemplate
|
|||||||
@Override
|
@Override
|
||||||
public <T> CloseableIterator<T> stream(SearchQuery query, final Class<T> clazz, final SearchResultMapper mapper) {
|
public <T> CloseableIterator<T> stream(SearchQuery query, final Class<T> clazz, final SearchResultMapper mapper) {
|
||||||
final long scrollTimeInMillis = TimeValue.timeValueMinutes(1).millis();
|
final long scrollTimeInMillis = TimeValue.timeValueMinutes(1).millis();
|
||||||
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz, mapper), clazz,
|
return doStream(scrollTimeInMillis, startScroll(scrollTimeInMillis, query, clazz, mapper), clazz, mapper);
|
||||||
mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> CloseableIterator<T> doStream(final long scrollTimeInMillis, final ScrolledPage<T> page,
|
private <T> CloseableIterator<T> doStream(final long scrollTimeInMillis, final ScrolledPage<T> page,
|
||||||
@ -1453,8 +1452,7 @@ public class ElasticsearchRestTemplate
|
|||||||
node = node.findValue("aliases");
|
node = node.findValue("aliases");
|
||||||
|
|
||||||
Map<String, AliasData> aliasData = mapper.readValue(mapper.writeValueAsString(node),
|
Map<String, AliasData> aliasData = mapper.readValue(mapper.writeValueAsString(node),
|
||||||
new TypeReference<Map<String, AliasData>>() {
|
new TypeReference<Map<String, AliasData>>() {});
|
||||||
});
|
|
||||||
|
|
||||||
Iterable<Map.Entry<String, AliasData>> aliasIter = aliasData.entrySet();
|
Iterable<Map.Entry<String, AliasData>> aliasIter = aliasData.entrySet();
|
||||||
List<AliasMetaData> aliasMetaDataList = new ArrayList<AliasMetaData>();
|
List<AliasMetaData> aliasMetaDataList = new ArrayList<AliasMetaData>();
|
||||||
|
@ -206,7 +206,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, EsClient<
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
|
MappingBuilder mappingBuilder = new MappingBuilder(elasticsearchConverter);
|
||||||
return putMapping(clazz, mappingBuilder.buildMapping(clazz));
|
return putMapping(clazz, mappingBuilder.buildPropertyMapping(clazz));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
|
throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e);
|
||||||
}
|
}
|
||||||
|
@ -27,16 +27,25 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
import org.springframework.data.elasticsearch.annotations.*;
|
import org.springframework.data.elasticsearch.annotations.CompletionContext;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.DynamicTemplates;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
import org.springframework.data.elasticsearch.core.completion.Completion;
|
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.mapping.PropertyHandler;
|
import org.springframework.data.mapping.PropertyHandler;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -61,34 +70,33 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
*/
|
*/
|
||||||
class MappingBuilder {
|
class MappingBuilder {
|
||||||
|
|
||||||
public static final String FIELD_DATA = "fielddata";
|
private static final String FIELD_DATA = "fielddata";
|
||||||
public static final String FIELD_STORE = "store";
|
private static final String FIELD_STORE = "store";
|
||||||
public static final String FIELD_TYPE = "type";
|
private static final String FIELD_TYPE = "type";
|
||||||
public static final String FIELD_INDEX = "index";
|
private static final String FIELD_INDEX = "index";
|
||||||
public static final String FIELD_FORMAT = "format";
|
private static final String FIELD_FORMAT = "format";
|
||||||
public static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
|
private static final String FIELD_SEARCH_ANALYZER = "search_analyzer";
|
||||||
public static final String FIELD_INDEX_ANALYZER = "analyzer";
|
private static final String FIELD_INDEX_ANALYZER = "analyzer";
|
||||||
public static final String FIELD_NORMALIZER = "normalizer";
|
private static final String FIELD_NORMALIZER = "normalizer";
|
||||||
public static final String FIELD_PROPERTIES = "properties";
|
private static final String FIELD_PROPERTIES = "properties";
|
||||||
public static final String FIELD_PARENT = "_parent";
|
private static final String FIELD_PARENT = "_parent";
|
||||||
public static final String FIELD_COPY_TO = "copy_to";
|
private static final String FIELD_COPY_TO = "copy_to";
|
||||||
public static final String FIELD_CONTEXT_NAME = "name";
|
private static final String FIELD_CONTEXT_NAME = "name";
|
||||||
public static final String FIELD_CONTEXT_TYPE = "type";
|
private static final String FIELD_CONTEXT_TYPE = "type";
|
||||||
public static final String FIELD_CONTEXT_PRECISION = "precision";
|
private static final String FIELD_CONTEXT_PRECISION = "precision";
|
||||||
public static final String FIELD_DYNAMIC_TEMPLATES = "dynamic_templates";
|
private static final String FIELD_DYNAMIC_TEMPLATES = "dynamic_templates";
|
||||||
|
|
||||||
public static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
|
private static final String COMPLETION_PRESERVE_SEPARATORS = "preserve_separators";
|
||||||
public static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
|
private static final String COMPLETION_PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
|
||||||
public static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
|
private static final String COMPLETION_MAX_INPUT_LENGTH = "max_input_length";
|
||||||
public static final String COMPLETION_CONTEXTS = "contexts";
|
private static final String COMPLETION_CONTEXTS = "contexts";
|
||||||
|
|
||||||
|
private static final String TYPE_VALUE_KEYWORD = "keyword";
|
||||||
|
private static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
||||||
|
private static final String TYPE_VALUE_COMPLETION = "completion";
|
||||||
|
|
||||||
public static final String TYPE_VALUE_KEYWORD = "keyword";
|
|
||||||
public static final String TYPE_VALUE_GEO_POINT = "geo_point";
|
|
||||||
public static final String TYPE_VALUE_COMPLETION = "completion";
|
|
||||||
public static final String TYPE_VALUE_GEO_HASH_PREFIX = "geohash_prefix";
|
|
||||||
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchRestTemplate.class);
|
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchRestTemplate.class);
|
||||||
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = SimpleTypeHolder.DEFAULT;
|
|
||||||
private final ElasticsearchConverter elasticsearchConverter;
|
private final ElasticsearchConverter elasticsearchConverter;
|
||||||
|
|
||||||
MappingBuilder(ElasticsearchConverter elasticsearchConverter) {
|
MappingBuilder(ElasticsearchConverter elasticsearchConverter) {
|
||||||
@ -101,7 +109,7 @@ class MappingBuilder {
|
|||||||
* @return JSON string
|
* @return JSON string
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
String buildMapping(Class<?> clazz) throws IOException {
|
String buildPropertyMapping(Class<?> clazz) throws IOException {
|
||||||
|
|
||||||
ElasticsearchPersistentEntity<?> entity = elasticsearchConverter.getMappingContext()
|
ElasticsearchPersistentEntity<?> entity = elasticsearchConverter.getMappingContext()
|
||||||
.getRequiredPersistentEntity(clazz);
|
.getRequiredPersistentEntity(clazz);
|
||||||
@ -157,62 +165,7 @@ class MappingBuilder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.isAnnotationPresent(Mapping.class)) {
|
buildPropertyMapping(builder, isRootObject, property);
|
||||||
|
|
||||||
String mappingPath = property.getRequiredAnnotation(Mapping.class).mappingPath();
|
|
||||||
if (!StringUtils.isEmpty(mappingPath)) {
|
|
||||||
|
|
||||||
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
|
||||||
if (mappings.exists()) {
|
|
||||||
builder.rawField(property.getFieldName(), mappings.getInputStream(), XContentType.JSON);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isGeoPointProperty = isGeoPointProperty(property);
|
|
||||||
boolean isCompletionProperty = isCompletionProperty(property);
|
|
||||||
boolean isNestedOrObjectProperty = isNestedOrObjectProperty(property);
|
|
||||||
|
|
||||||
Field fieldAnnotation = property.findAnnotation(Field.class);
|
|
||||||
if (!isGeoPointProperty && !isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {
|
|
||||||
|
|
||||||
if (fieldAnnotation == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
|
|
||||||
ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
|
|
||||||
? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
|
|
||||||
: null;
|
|
||||||
|
|
||||||
mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty,
|
|
||||||
fieldAnnotation.type(), fieldAnnotation);
|
|
||||||
|
|
||||||
if (isNestedOrObjectProperty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiField multiField = property.findAnnotation(MultiField.class);
|
|
||||||
|
|
||||||
if (isGeoPointProperty) {
|
|
||||||
applyGeoPointFieldMapping(builder, property);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCompletionProperty) {
|
|
||||||
CompletionField completionField = property.findAnnotation(CompletionField.class);
|
|
||||||
applyCompletionFieldMapping(builder, property, completionField);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isRootObject && fieldAnnotation != null && property.isIdProperty()) {
|
|
||||||
applyDefaultIdFieldMapping(builder, property);
|
|
||||||
} else if (multiField != null) {
|
|
||||||
addMultiFieldMapping(builder, property, multiField, isNestedOrObjectProperty);
|
|
||||||
} else if (fieldAnnotation != null) {
|
|
||||||
addSingleFieldMapping(builder, property, fieldAnnotation, isNestedOrObjectProperty);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("error mapping property with name {}", property.getName(), e);
|
logger.warn("error mapping property with name {}", property.getName(), e);
|
||||||
}
|
}
|
||||||
@ -224,6 +177,67 @@ class MappingBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
|
||||||
|
ElasticsearchPersistentProperty property) throws IOException {
|
||||||
|
|
||||||
|
if (property.isAnnotationPresent(Mapping.class)) {
|
||||||
|
|
||||||
|
String mappingPath = property.getRequiredAnnotation(Mapping.class).mappingPath();
|
||||||
|
if (!StringUtils.isEmpty(mappingPath)) {
|
||||||
|
|
||||||
|
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
||||||
|
if (mappings.exists()) {
|
||||||
|
builder.rawField(property.getFieldName(), mappings.getInputStream(), XContentType.JSON);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isGeoPointProperty = isGeoPointProperty(property);
|
||||||
|
boolean isCompletionProperty = isCompletionProperty(property);
|
||||||
|
boolean isNestedOrObjectProperty = isNestedOrObjectProperty(property);
|
||||||
|
|
||||||
|
Field fieldAnnotation = property.findAnnotation(Field.class);
|
||||||
|
if (!isGeoPointProperty && !isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {
|
||||||
|
|
||||||
|
if (fieldAnnotation == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
|
||||||
|
ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
|
||||||
|
? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
|
||||||
|
: null;
|
||||||
|
|
||||||
|
mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty,
|
||||||
|
fieldAnnotation.type(), fieldAnnotation);
|
||||||
|
|
||||||
|
if (isNestedOrObjectProperty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiField multiField = property.findAnnotation(MultiField.class);
|
||||||
|
|
||||||
|
if (isGeoPointProperty) {
|
||||||
|
applyGeoPointFieldMapping(builder, property);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCompletionProperty) {
|
||||||
|
CompletionField completionField = property.findAnnotation(CompletionField.class);
|
||||||
|
applyCompletionFieldMapping(builder, property, completionField);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRootObject && fieldAnnotation != null && property.isIdProperty()) {
|
||||||
|
applyDefaultIdFieldMapping(builder, property);
|
||||||
|
} else if (multiField != null) {
|
||||||
|
addMultiFieldMapping(builder, property, multiField, isNestedOrObjectProperty);
|
||||||
|
} else if (fieldAnnotation != null) {
|
||||||
|
addSingleFieldMapping(builder, property, fieldAnnotation, isNestedOrObjectProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasRelevantAnnotation(ElasticsearchPersistentProperty property) {
|
private boolean hasRelevantAnnotation(ElasticsearchPersistentProperty property) {
|
||||||
|
|
||||||
return property.findAnnotation(Field.class) != null || property.findAnnotation(MultiField.class) != null
|
return property.findAnnotation(Field.class) != null || property.findAnnotation(MultiField.class) != null
|
||||||
@ -321,6 +335,7 @@ class MappingBuilder {
|
|||||||
|
|
||||||
private void addFieldMappingParameters(XContentBuilder builder, Object annotation, boolean nestedOrObjectField)
|
private void addFieldMappingParameters(XContentBuilder builder, Object annotation, boolean nestedOrObjectField)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
boolean index = true;
|
boolean index = true;
|
||||||
boolean store = false;
|
boolean store = false;
|
||||||
boolean fielddata = false;
|
boolean fielddata = false;
|
||||||
|
@ -22,6 +22,7 @@ import org.springframework.data.mapping.context.AbstractMappingContext;
|
|||||||
import org.springframework.data.mapping.model.Property;
|
import org.springframework.data.mapping.model.Property;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleElasticsearchMappingContext
|
* SimpleElasticsearchMappingContext
|
||||||
@ -30,10 +31,11 @@ import org.springframework.data.util.TypeInformation;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class SimpleElasticsearchMappingContext extends
|
public class SimpleElasticsearchMappingContext
|
||||||
AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> implements ApplicationContextAware {
|
extends AbstractMappingContext<SimpleElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty>
|
||||||
|
implements ApplicationContextAware {
|
||||||
|
|
||||||
private ApplicationContext context;
|
private @Nullable ApplicationContext context;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
protected <T> SimpleElasticsearchPersistentEntity<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||||
|
@ -55,21 +55,22 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
private final StandardEvaluationContext context;
|
private final StandardEvaluationContext context;
|
||||||
private final SpelExpressionParser parser;
|
private final SpelExpressionParser parser;
|
||||||
|
|
||||||
private String indexName;
|
private @Nullable String indexName;
|
||||||
private String indexType;
|
private @Nullable String indexType;
|
||||||
private boolean useServerConfiguration;
|
private boolean useServerConfiguration;
|
||||||
private short shards;
|
private short shards;
|
||||||
private short replicas;
|
private short replicas;
|
||||||
private String refreshInterval;
|
private @Nullable String refreshInterval;
|
||||||
private String indexStoreType;
|
private @Nullable String indexStoreType;
|
||||||
private String parentType;
|
private @Nullable String parentType;
|
||||||
private ElasticsearchPersistentProperty parentIdProperty;
|
private @Nullable ElasticsearchPersistentProperty parentIdProperty;
|
||||||
private ElasticsearchPersistentProperty scoreProperty;
|
private @Nullable ElasticsearchPersistentProperty scoreProperty;
|
||||||
private String settingPath;
|
private @Nullable String settingPath;
|
||||||
private VersionType versionType;
|
private VersionType versionType;
|
||||||
private boolean createIndexAndMapping;
|
private boolean createIndexAndMapping;
|
||||||
|
|
||||||
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
|
public SimpleElasticsearchPersistentEntity(TypeInformation<T> typeInformation) {
|
||||||
|
|
||||||
super(typeInformation);
|
super(typeInformation);
|
||||||
this.context = new StandardEvaluationContext();
|
this.context = new StandardEvaluationContext();
|
||||||
this.parser = new SpelExpressionParser();
|
this.parser = new SpelExpressionParser();
|
||||||
@ -104,7 +105,7 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
@Override
|
@Override
|
||||||
public String getIndexName() {
|
public String getIndexName() {
|
||||||
|
|
||||||
if(indexName != null) {
|
if (indexName != null) {
|
||||||
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
|
Expression expression = parser.parseExpression(indexName, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
return expression.getValue(context, String.class);
|
return expression.getValue(context, String.class);
|
||||||
}
|
}
|
||||||
@ -115,7 +116,7 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
@Override
|
@Override
|
||||||
public String getIndexType() {
|
public String getIndexType() {
|
||||||
|
|
||||||
if(indexType != null) {
|
if (indexType != null) {
|
||||||
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
return expression.getValue(context, String.class);
|
return expression.getValue(context, String.class);
|
||||||
}
|
}
|
||||||
@ -192,9 +193,10 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
ElasticsearchPersistentProperty parentProperty = this.parentIdProperty;
|
ElasticsearchPersistentProperty parentProperty = this.parentIdProperty;
|
||||||
|
|
||||||
if (parentProperty != null) {
|
if (parentProperty != null) {
|
||||||
throw new MappingException(
|
throw new MappingException(String.format(
|
||||||
String.format("Attempt to add parent property %s but already have property %s registered "
|
"Attempt to add parent property %s but already have property %s registered "
|
||||||
+ "as parent property. Check your mapping configuration!", property.getField(), parentProperty.getField()));
|
+ "as parent property. Check your mapping configuration!",
|
||||||
|
property.getField(), parentProperty.getField()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Parent parentAnnotation = property.findAnnotation(Parent.class);
|
Parent parentAnnotation = property.findAnnotation(Parent.class);
|
||||||
@ -207,9 +209,10 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
ElasticsearchPersistentProperty scoreProperty = this.scoreProperty;
|
ElasticsearchPersistentProperty scoreProperty = this.scoreProperty;
|
||||||
|
|
||||||
if (scoreProperty != null) {
|
if (scoreProperty != null) {
|
||||||
throw new MappingException(
|
throw new MappingException(String.format(
|
||||||
String.format("Attempt to add score property %s but already have property %s registered "
|
"Attempt to add score property %s but already have property %s registered "
|
||||||
+ "as score property. Check your mapping configuration!", property.getField(), scoreProperty.getField()));
|
+ "as score property. Check your mapping configuration!",
|
||||||
|
property.getField(), scoreProperty.getField()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scoreProperty = property;
|
this.scoreProperty = property;
|
||||||
|
@ -27,6 +27,7 @@ import org.springframework.data.mapping.PersistentEntity;
|
|||||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||||
import org.springframework.data.mapping.model.Property;
|
import org.springframework.data.mapping.model.Property;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +48,7 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
private final boolean isScore;
|
private final boolean isScore;
|
||||||
private final boolean isParent;
|
private final boolean isParent;
|
||||||
private final boolean isId;
|
private final boolean isId;
|
||||||
private final String annotatedFieldName;
|
private final @Nullable String annotatedFieldName;
|
||||||
|
|
||||||
public SimpleElasticsearchPersistentProperty(Property property,
|
public SimpleElasticsearchPersistentProperty(Property property,
|
||||||
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||||
@ -59,20 +60,21 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
this.isScore = isAnnotationPresent(Score.class);
|
this.isScore = isAnnotationPresent(Score.class);
|
||||||
this.isParent = isAnnotationPresent(Parent.class);
|
this.isParent = isAnnotationPresent(Parent.class);
|
||||||
|
|
||||||
if (isVersionProperty() && getType() != Long.class) {
|
if (isVersionProperty() && !getType().equals(Long.class)) {
|
||||||
throw new MappingException(String.format("Version property %s must be of type Long!", property.getName()));
|
throw new MappingException(String.format("Version property %s must be of type Long!", property.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isScore && !Arrays.asList(Float.TYPE, Float.class).contains(getType())) {
|
if (isScore && !getType().equals(Float.TYPE) && !getType().equals(Float.class)) {
|
||||||
throw new MappingException(
|
throw new MappingException(
|
||||||
String.format("Score property %s must be either of type float or Float!", property.getName()));
|
String.format("Score property %s must be either of type float or Float!", property.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isParent && getType() != String.class) {
|
if (isParent && !getType().equals(String.class)) {
|
||||||
throw new MappingException(String.format("Parent property %s must be of type String!", property.getName()));
|
throw new MappingException(String.format("Parent property %s must be of type String!", property.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String getAnnotatedFieldName() {
|
private String getAnnotatedFieldName() {
|
||||||
|
|
||||||
if (isAnnotationPresent(Field.class)) {
|
if (isAnnotationPresent(Field.class)) {
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Infrastructure for the Elasticsearch document-to-object mapping subsystem.
|
||||||
|
*/
|
||||||
|
@org.springframework.lang.NonNullApi
|
||||||
|
package org.springframework.data.elasticsearch.core.mapping;
|
@ -19,11 +19,12 @@ package org.springframework.data.elasticsearch.core;
|
|||||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
|
||||||
import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,12 +32,32 @@ import java.util.Map;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.skyscreamer.jsonassert.JSONAssert;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Parent;
|
||||||
import org.springframework.data.elasticsearch.builder.SampleInheritedEntityBuilder;
|
import org.springframework.data.elasticsearch.builder.SampleInheritedEntityBuilder;
|
||||||
|
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||||
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||||
import org.springframework.data.elasticsearch.entities.*;
|
import org.springframework.data.elasticsearch.entities.Book;
|
||||||
|
import org.springframework.data.elasticsearch.entities.CopyToEntity;
|
||||||
|
import org.springframework.data.elasticsearch.entities.GeoEntity;
|
||||||
|
import org.springframework.data.elasticsearch.entities.Group;
|
||||||
|
import org.springframework.data.elasticsearch.entities.NormalizerEntity;
|
||||||
|
import org.springframework.data.elasticsearch.entities.SampleInheritedEntity;
|
||||||
|
import org.springframework.data.elasticsearch.entities.SampleTransientEntity;
|
||||||
|
import org.springframework.data.elasticsearch.entities.SimpleRecursiveEntity;
|
||||||
|
import org.springframework.data.elasticsearch.entities.StockPrice;
|
||||||
|
import org.springframework.data.elasticsearch.entities.User;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@ -64,30 +85,33 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
elasticsearchTemplate.refresh(SimpleRecursiveEntity.class);
|
elasticsearchTemplate.refresh(SimpleRecursiveEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void testInfiniteLoopAvoidance() throws IOException, JSONException {
|
public void testInfiniteLoopAvoidance() throws IOException, JSONException {
|
||||||
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\""
|
|
||||||
|
String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\""
|
||||||
+ "type\":\"text\",\"index\":false," + "\"analyzer\":\"standard\"}}}}";
|
+ "type\":\"text\",\"index\":false," + "\"analyzer\":\"standard\"}}}}";
|
||||||
|
|
||||||
String mapping = getMappingBuilder().buildMapping(SampleTransientEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(SampleTransientEntity.class);
|
||||||
|
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void shouldUseValueFromAnnotationType() throws IOException, JSONException {
|
public void shouldUseValueFromAnnotationType() throws IOException, JSONException {
|
||||||
|
|
||||||
// Given
|
// Given
|
||||||
final String expected = "{\"price\":{\"properties\":{\"price\":{\"store\":false,\"type\":\"double\"}}}}";
|
String expected = "{\"price\":{\"properties\":{\"price\":{\"store\":false,\"type\":\"double\"}}}}";
|
||||||
|
|
||||||
// When
|
// When
|
||||||
String mapping = getMappingBuilder().buildMapping(StockPrice.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(StockPrice.class);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-530
|
@Test // DATAES-530
|
||||||
public void shouldAddStockPriceDocumentToIndex() throws IOException {
|
public void shouldAddStockPriceDocumentToIndex() {
|
||||||
|
|
||||||
// Given
|
// Given
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@ -111,34 +135,31 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
assertThat(entry.getPrice(), is(BigDecimal.valueOf(price)));
|
assertThat(entry.getPrice(), is(BigDecimal.valueOf(price)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void shouldCreateMappingForSpecifiedParentType() throws IOException, JSONException {
|
public void shouldCreateMappingForSpecifiedParentType() throws IOException, JSONException {
|
||||||
final String expected = "{\"mapping\":{\"_parent\":{\"type\":\"parentType\"},\"properties\":{}}}";
|
|
||||||
|
|
||||||
String mapping = getMappingBuilder().buildMapping(MinimalChildEntity.class);
|
String expected = "{\"mapping\":{\"_parent\":{\"type\":\"parentType\"},\"properties\":{}}}";
|
||||||
|
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
String mapping = getMappingBuilder().buildPropertyMapping(MinimalChildEntity.class);
|
||||||
|
|
||||||
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@Test // DATAES-76
|
||||||
* DATAES-76
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void shouldBuildMappingWithSuperclass() throws IOException, JSONException {
|
public void shouldBuildMappingWithSuperclass() throws IOException, JSONException {
|
||||||
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\""
|
|
||||||
|
String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\""
|
||||||
+ "type\":\"text\",\"index\":false,\"analyzer\":\"standard\"}" + ",\"createdDate\":{\"store\":false,"
|
+ "type\":\"text\",\"index\":false,\"analyzer\":\"standard\"}" + ",\"createdDate\":{\"store\":false,"
|
||||||
+ "\"type\":\"date\",\"index\":false}}}}";
|
+ "\"type\":\"date\",\"index\":false}}}}";
|
||||||
|
|
||||||
String mapping = getMappingBuilder().buildMapping(SampleInheritedEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(SampleInheritedEntity.class);
|
||||||
|
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@Test // DATAES-76
|
||||||
* DATAES-76
|
public void shouldAddSampleInheritedEntityDocumentToIndex() {
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void shouldAddSampleInheritedEntityDocumentToIndex() throws IOException {
|
|
||||||
// Given
|
// Given
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@ -156,13 +177,15 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
List<SampleInheritedEntity> result = elasticsearchTemplate.queryForList(searchQuery, SampleInheritedEntity.class);
|
List<SampleInheritedEntity> result = elasticsearchTemplate.queryForList(searchQuery, SampleInheritedEntity.class);
|
||||||
// Then
|
// Then
|
||||||
assertThat(result.size(), is(1));
|
assertThat(result.size(), is(1));
|
||||||
|
|
||||||
SampleInheritedEntity entry = result.get(0);
|
SampleInheritedEntity entry = result.get(0);
|
||||||
assertThat(entry.getCreatedDate(), is(createdDate));
|
assertThat(entry.getCreatedDate(), is(createdDate));
|
||||||
assertThat(entry.getMessage(), is(message));
|
assertThat(entry.getMessage(), is(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void shouldBuildMappingsForGeoPoint() throws IOException, JSONException {
|
public void shouldBuildMappingsForGeoPoint() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
String expected = "{\"geo-test-index\": {\"properties\": {" + "\"pointA\":{\"type\":\"geo_point\"},"
|
String expected = "{\"geo-test-index\": {\"properties\": {" + "\"pointA\":{\"type\":\"geo_point\"},"
|
||||||
+ "\"pointB\":{\"type\":\"geo_point\"}," + "\"pointC\":{\"type\":\"geo_point\"},"
|
+ "\"pointB\":{\"type\":\"geo_point\"}," + "\"pointC\":{\"type\":\"geo_point\"},"
|
||||||
@ -170,17 +193,15 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping;
|
String mapping;
|
||||||
mapping = getMappingBuilder().buildMapping(GeoEntity.class);
|
mapping = getMappingBuilder().buildPropertyMapping(GeoEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Test // DATAES-260 - StackOverflow when two reverse relationship.
|
||||||
* DATAES-260 - StacOverflow when two reverse relationship.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void shouldHandleReverseRelationship() {
|
public void shouldHandleReverseRelationship() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
elasticsearchTemplate.createIndex(User.class);
|
elasticsearchTemplate.createIndex(User.class);
|
||||||
elasticsearchTemplate.putMapping(User.class);
|
elasticsearchTemplate.putMapping(User.class);
|
||||||
@ -189,21 +210,21 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
// when
|
// when
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-285
|
||||||
public void shouldMapBooks() {
|
public void shouldMapBooks() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
elasticsearchTemplate.createIndex(Book.class);
|
elasticsearchTemplate.createIndex(Book.class);
|
||||||
elasticsearchTemplate.putMapping(Book.class);
|
elasticsearchTemplate.putMapping(Book.class);
|
||||||
// when
|
// when
|
||||||
// then
|
// then
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-420
|
@Test // DATAES-420
|
||||||
public void shouldUseBothAnalyzer() {
|
public void shouldUseBothAnalyzer() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
elasticsearchTemplate.deleteIndex(Book.class);
|
elasticsearchTemplate.deleteIndex(Book.class);
|
||||||
elasticsearchTemplate.createIndex(Book.class);
|
elasticsearchTemplate.createIndex(Book.class);
|
||||||
@ -224,7 +245,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-492
|
@Test // DATAES-492
|
||||||
public void shouldUseKeywordNormalizer() throws IOException {
|
public void shouldUseKeywordNormalizer() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
elasticsearchTemplate.deleteIndex(NormalizerEntity.class);
|
elasticsearchTemplate.deleteIndex(NormalizerEntity.class);
|
||||||
@ -245,7 +266,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-503
|
@Test // DATAES-503
|
||||||
public void shouldUseCopyTo() throws IOException {
|
public void shouldUseCopyTo() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
elasticsearchTemplate.deleteIndex(CopyToEntity.class);
|
elasticsearchTemplate.deleteIndex(CopyToEntity.class);
|
||||||
@ -259,107 +280,188 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
Map fieldLastName = (Map) properties.get("lastName");
|
Map fieldLastName = (Map) properties.get("lastName");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
List<String> copyToValue = Arrays.asList("name");
|
List<String> copyToValue = Collections.singletonList("name");
|
||||||
assertThat(fieldFirstName.get("copy_to"), equalTo(copyToValue));
|
assertThat(fieldFirstName.get("copy_to"), equalTo(copyToValue));
|
||||||
assertThat(fieldLastName.get("copy_to"), equalTo(copyToValue));
|
assertThat(fieldLastName.get("copy_to"), equalTo(copyToValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnId() throws IOException, JSONException {
|
public void shouldUseFieldNameOnId() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true}"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true}" + "}}}";
|
+ "}}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.IdEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.IdEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnText() throws IOException, JSONException {
|
public void shouldUseFieldNameOnText() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
|
||||||
+ "\"text-property\":{\"store\":false,\"type\":\"text\"}" + "}}}";
|
+ "\"text-property\":{\"store\":false,\"type\":\"text\"}" + "}}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.TextEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.TextEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnMapping() throws IOException, JSONException {
|
public void shouldUseFieldNameOnMapping() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
|
||||||
+ "\"mapping-property\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"}" + "}}}";
|
+ "\"mapping-property\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"}" + "}}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.MappingEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.MappingEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnGeoPoint() throws IOException, JSONException {
|
public void shouldUseFieldNameOnGeoPoint() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true}," + "\"geopoint-property\":{\"type\":\"geo_point\"}"
|
+ "\"geopoint-property\":{\"type\":\"geo_point\"}" + "}}}";
|
||||||
+ "}}}";
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.GeoPointEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.GeoPointEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnCircularEntity() throws IOException, JSONException {
|
public void shouldUseFieldNameOnCircularEntity() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
|
||||||
+ "\"circular-property\":{\"type\":\"object\",\"properties\":{\"id-property\":{\"store\":false}}}" + "}}}";
|
+ "\"circular-property\":{\"type\":\"object\",\"properties\":{\"id-property\":{\"store\":false}}}" + "}}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.CircularEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.CircularEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnCompletion() throws IOException, JSONException {
|
public void shouldUseFieldNameOnCompletion() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
|
||||||
+ "\"completion-property\":{\"type\":\"completion\",\"max_input_length\":100,\"preserve_position_increments\":true,\"preserve_separators\":true,\"search_analyzer\":\"simple\",\"analyzer\":\"simple\"},\"completion-property\":{\"store\":false}"
|
+ "\"completion-property\":{\"type\":\"completion\",\"max_input_length\":100,\"preserve_position_increments\":true,\"preserve_separators\":true,\"search_analyzer\":\"simple\",\"analyzer\":\"simple\"},\"completion-property\":{\"store\":false}"
|
||||||
+ "}}}";
|
+ "}}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.CompletionEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.CompletionEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-568
|
@Test // DATAES-568
|
||||||
public void shouldUseFieldNameOnMultiField() throws IOException, JSONException {
|
public void shouldUseFieldNameOnMultiField() throws IOException, JSONException {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final String expected = "{\"fieldname-type\":{\"properties\":{"
|
String expected = "{\"fieldname-type\":{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
|
||||||
+ "\"multifield-property\":{\"store\":false,\"type\":\"text\",\"analyzer\":\"whitespace\",\"fields\":{\"prefix\":{\"store\":false,\"type\":\"text\",\"analyzer\":\"stop\",\"search_analyzer\":\"standard\"}}}"
|
+ "\"multifield-property\":{\"store\":false,\"type\":\"text\",\"analyzer\":\"whitespace\",\"fields\":{\"prefix\":{\"store\":false,\"type\":\"text\",\"analyzer\":\"stop\",\"search_analyzer\":\"standard\"}}}"
|
||||||
+ "}}}";
|
+ "}}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildMapping(FieldNameEntity.MultiFieldEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.MultiFieldEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
JSONAssert.assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
static class FieldNameEntity {
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class IdEntity {
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class TextEntity {
|
||||||
|
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
|
||||||
|
@Field(name = "text-property", type = FieldType.Text) //
|
||||||
|
private String textProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class MappingEntity {
|
||||||
|
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
|
||||||
|
@Field("mapping-property") @Mapping(mappingPath = "/mappings/test-field-analyzed-mappings.json") //
|
||||||
|
private byte[] mappingProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class GeoPointEntity {
|
||||||
|
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
|
||||||
|
@Field("geopoint-property") private GeoPoint geoPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class CircularEntity {
|
||||||
|
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
|
||||||
|
@Field(name = "circular-property", type = FieldType.Object, ignoreFields = { "circular-property" }) //
|
||||||
|
private CircularEntity circularProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class CompletionEntity {
|
||||||
|
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
|
||||||
|
@Field("completion-property") @CompletionField(maxInputLength = 100) //
|
||||||
|
private Completion suggest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
||||||
|
static class MultiFieldEntity {
|
||||||
|
|
||||||
|
@Id @Field("id-property") private String id;
|
||||||
|
|
||||||
|
@Field("multifield-property") //
|
||||||
|
@MultiField(mainField = @Field(type = FieldType.Text, analyzer = "whitespace"), otherFields = {
|
||||||
|
@InnerField(suffix = "prefix", type = FieldType.Text, analyzer = "stop", searchAnalyzer = "standard") }) //
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MinimalChildEntity
|
||||||
|
*
|
||||||
|
* @author Peter-josef Meisch
|
||||||
|
*/
|
||||||
|
@Document(indexName = "test-index-minimal", type = "mapping")
|
||||||
|
static class MinimalChildEntity {
|
||||||
|
|
||||||
|
@Id private String id;
|
||||||
|
|
||||||
|
@Parent(type = "parentType") private String parentId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntity;
|
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntity;
|
||||||
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntityTwo;
|
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntityTwo;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -20,26 +22,30 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||||
public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests {
|
public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests {
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void testCorrectDynamicTemplatesMappings() throws IOException {
|
public void testCorrectDynamicTemplatesMappings() throws IOException {
|
||||||
String mapping = getMappingBuilder().buildMapping(SampleDynamicTemplatesEntity.class);
|
|
||||||
|
String mapping = getMappingBuilder().buildPropertyMapping(SampleDynamicTemplatesEntity.class);
|
||||||
|
|
||||||
String EXPECTED_MAPPING_ONE = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":"
|
String EXPECTED_MAPPING_ONE = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":"
|
||||||
+ "[{\"with_custom_analyzer\":{"
|
+ "[{\"with_custom_analyzer\":{"
|
||||||
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
|
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
|
||||||
+ "\"path_match\":\"names.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}}";
|
+ "\"path_match\":\"names.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}}";
|
||||||
Assert.assertEquals(EXPECTED_MAPPING_ONE, mapping);
|
|
||||||
|
assertEquals(EXPECTED_MAPPING_ONE, mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void testCorrectDynamicTemplatesMappingsTwo() throws IOException {
|
public void testCorrectDynamicTemplatesMappingsTwo() throws IOException {
|
||||||
String mapping = getMappingBuilder().buildMapping(SampleDynamicTemplatesEntityTwo.class);
|
|
||||||
|
String mapping = getMappingBuilder().buildPropertyMapping(SampleDynamicTemplatesEntityTwo.class);
|
||||||
String EXPECTED_MAPPING_TWO = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":"
|
String EXPECTED_MAPPING_TWO = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":"
|
||||||
+ "[{\"with_custom_analyzer\":{"
|
+ "[{\"with_custom_analyzer\":{"
|
||||||
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
|
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
|
||||||
+ "\"path_match\":\"names.*\"}}," + "{\"participantA1_with_custom_analyzer\":{"
|
+ "\"path_match\":\"names.*\"}}," + "{\"participantA1_with_custom_analyzer\":{"
|
||||||
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
|
+ "\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"},"
|
||||||
+ "\"path_match\":\"participantA1.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}}";
|
+ "\"path_match\":\"participantA1.*\"}}]," + "\"properties\":{\"names\":{\"type\":\"object\"}}}}";
|
||||||
Assert.assertEquals(EXPECTED_MAPPING_TWO, mapping);
|
|
||||||
|
assertEquals(EXPECTED_MAPPING_TWO, mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.entities.SampleDateMappingEntity;
|
import org.springframework.data.elasticsearch.entities.SampleDateMappingEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,11 +36,11 @@ public class SimpleElasticsearchDateMappingTests extends MappingContextBaseTests
|
|||||||
+ "\"defaultFormatDate\":{\"store\":false,\"type\":\"date\"},\"basicFormatDate\":{\"store\":false,\""
|
+ "\"defaultFormatDate\":{\"store\":false,\"type\":\"date\"},\"basicFormatDate\":{\"store\":false,\""
|
||||||
+ "type\":\"date\",\"format\":\"basic_date\"}}}}";
|
+ "type\":\"date\",\"format\":\"basic_date\"}}}}";
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-568
|
||||||
public void testCorrectDateMappings() throws IOException {
|
public void testCorrectDateMappings() throws IOException {
|
||||||
|
|
||||||
String mapping = getMappingBuilder().buildMapping(SampleDateMappingEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(SampleDateMappingEntity.class);
|
||||||
|
|
||||||
Assert.assertEquals(EXPECTED_MAPPING, mapping);
|
assertEquals(EXPECTED_MAPPING, mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/package org.springframework.data.elasticsearch.entities;
|
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
|
||||||
import org.springframework.data.elasticsearch.core.completion.Completion;
|
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Peter-Josef Meisch
|
|
||||||
*/
|
|
||||||
public class FieldNameEntity {
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class IdEntity {
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class TextEntity {
|
|
||||||
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Field(name = "text-property", type = FieldType.Text)
|
|
||||||
private String textProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class MappingEntity {
|
|
||||||
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Field("mapping-property") @Mapping(mappingPath = "/mappings/test-field-analyzed-mappings.json")
|
|
||||||
private byte[] mappingProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class GeoPointEntity {
|
|
||||||
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Field("geopoint-property")
|
|
||||||
private GeoPoint geoPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class CircularEntity {
|
|
||||||
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Field(name = "circular-property", type = FieldType.Object,
|
|
||||||
ignoreFields = { "circular-property" })
|
|
||||||
private CircularEntity circularProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class CompletionEntity {
|
|
||||||
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Field("completion-property")
|
|
||||||
@CompletionField(maxInputLength = 100)
|
|
||||||
private Completion suggest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = "fieldname-index", type = "fieldname-type")
|
|
||||||
public static class MultiFieldEntity {
|
|
||||||
|
|
||||||
@Id @Field("id-property")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Field("multifield-property")
|
|
||||||
@MultiField(
|
|
||||||
mainField = @Field(type = FieldType.Text, analyzer = "whitespace"),
|
|
||||||
otherFields = {
|
|
||||||
@InnerField(suffix = "prefix", type = FieldType.Text, analyzer = "stop", searchAnalyzer = "standard")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
private String description;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.elasticsearch.entities;
|
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Parent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MinimalChildEntity
|
|
||||||
*
|
|
||||||
* @author Peter-josef Meisch
|
|
||||||
*/
|
|
||||||
@Document(indexName = "test-index-minimal", type = "mapping")
|
|
||||||
public class MinimalChildEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Parent(type = "parentType")
|
|
||||||
private String parentId;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user