Skip to content

Commit 469646b

Browse files
author
Luc Boutier
committed
Fix mapping issues for date and enums that must be considered as primitive and not objects.
1 parent b29d2f6 commit 469646b

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/FieldsMappingBuilder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ private void parseFieldMappings(Class<?> clazz, Map<String, Object> classDefinit
7474
processFacetAnnotation(facetFields, filteredFields, esFieldName, indexable);
7575

7676
// process the fields
77-
if (ClassUtils.isPrimitiveOrWrapper(indexable.getType()) || indexable.getType() == String.class) {
77+
if (ClassUtils.isPrimitiveOrWrapper(indexable.getType()) || indexable.getType() == String.class || indexable.getType() == Date.class) {
7878
processStringOrPrimitive(clazz, propertiesDefinitionMap, pathPrefix, indexable);
79+
} else if (indexable.getType().isEnum()) {
80+
StringField annotation = indexable.getAnnotation(StringField.class);
81+
if (annotation != null) {
82+
processStringOrPrimitive(clazz, propertiesDefinitionMap, pathPrefix, indexable);
83+
}
7984
} else {
8085
Class<?> arrayType = indexable.getComponentType();
8186
// mapping of a complex field
8287
if (arrayType != null) {
8388
// process the array type.
84-
if (ClassUtils.isPrimitiveOrWrapper(arrayType) || arrayType == String.class) {
89+
if (ClassUtils.isPrimitiveOrWrapper(arrayType) || arrayType == String.class || indexable.getType() == Date.class) {
8590
processStringOrPrimitive(clazz, propertiesDefinitionMap, pathPrefix, indexable);
8691
} else if (arrayType.isEnum()) {
8792
// if this is an enum and there is a String

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/parser/BooleanFieldAnnotationParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.elasticsearch.common.logging.Loggers;
88
import org.elasticsearch.mapping.Indexable;
99
import org.elasticsearch.mapping.MappingBuilder;
10-
import org.elasticsearch.mapping.MappingException;
1110

1211
/**
1312
* Parse a {@link BooleanField} annotation.

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/parser/ObjectFieldAnnotationParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public void parseAnnotation(ObjectField annotation, Map<String, Object> fieldDef
4444
// nested types can provide replacement class to be managed. This can be usefull to override map default type for example.
4545
Class<?> replaceClass = objectClass.equals(ObjectField.class) ? indexable.getType() : objectClass;
4646
try {
47+
if(replaceClass.getName().equals("alien4cloud.model.components.PropertyDefinition")) {
48+
LOGGER.info("Process class {}", replaceClass.getName());
49+
}
50+
4751
this.fieldsMappingBuilder.parseFieldMappings(replaceClass, fieldDefinition, facets, filters, fetchContext, indexable.getName() + ".");
4852
} catch (IntrospectionException e) {
4953
LOGGER.error("Fail to parse object class <" + replaceClass.getName() + ">", e);

0 commit comments

Comments
 (0)