Skip to content

Commit 46a0d5f

Browse files
author
Luc Boutier
committed
- Fix array or collection check.
- Do that in a minor update 1.5.1
1 parent 784e473 commit 46a0d5f

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

elasticsearch-annotations/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.alien4cloud</groupId>
66
<artifactId>elasticsearch-mapping-parent</artifactId>
7-
<version>1.6.0-SNAPSHOT</version>
7+
<version>1.5.1-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>elasticsearch-annotations</artifactId>

elasticsearch-mapping/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.alien4cloud</groupId>
55
<artifactId>elasticsearch-mapping-parent</artifactId>
6-
<version>1.6.0-SNAPSHOT</version>
6+
<version>1.5.1-SNAPSHOT</version>
77
</parent>
88

99
<artifactId>elasticsearch-mapping</artifactId>

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ private void parseFieldMappings(Class<?> clazz, Map<String, Object> classDefinit
9898

9999
private void processComplexOrArray(Class<?> clazz, List<IFacetBuilderHelper> facetFields, List<IFilterBuilderHelper> filteredFields, String pathPrefix,
100100
Map<String, Object> propertiesDefinitionMap, Indexable indexable) {
101-
Class<?> arrayType = indexable.getComponentType();
102-
Class<?> mapValueType = indexable.getComponentType(1);
103101
// mapping of a complex field
104-
if (arrayType != null && mapValueType == null) {
102+
if (indexable.isArrayOrCollection()) {
103+
Class<?> arrayType = indexable.getComponentType();
105104
// process the array type.
106105
if (ClassUtils.isPrimitiveOrWrapper(arrayType) || arrayType == String.class || indexable.getType() == Date.class) {
107106
processStringOrPrimitive(clazz, propertiesDefinitionMap, pathPrefix, indexable);
@@ -319,19 +318,22 @@ private void processComplexType(Class<?> clazz, Map<String, Object> propertiesDe
319318
List<IFilterBuilderHelper> filters, List<IFacetBuilderHelper> facets) {
320319
NestedObjectFieldAnnotationParser nested = new NestedObjectFieldAnnotationParser(this, filters, facets);
321320
processFieldAnnotation(NestedObject.class, nested, propertiesDefinitionMap, pathPrefix, indexable);
322-
ObjectFieldAnnotationParser objectFieldAnnotationParser = new ObjectFieldAnnotationParser(this, filters, facets);
323-
processFieldAnnotation(ObjectField.class, objectFieldAnnotationParser, propertiesDefinitionMap, pathPrefix, indexable);
324-
// by default we consider the complex object as an object mapping and process recursive mapping of every field just as ES would process based on dynamic
325-
// mapping
326321

327322
if (propertiesDefinitionMap.get(indexable.getName()) == null) {
328-
// Define mapping as object
329-
Map<String, Object> fieldDefinition = (Map<String, Object>) propertiesDefinitionMap.get(indexable.getName());
330-
if (fieldDefinition == null) {
331-
fieldDefinition = new HashMap<String, Object>();
332-
propertiesDefinitionMap.put(indexable.getName(), fieldDefinition);
323+
ObjectFieldAnnotationParser objectFieldAnnotationParser = new ObjectFieldAnnotationParser(this, filters, facets);
324+
processFieldAnnotation(ObjectField.class, objectFieldAnnotationParser, propertiesDefinitionMap, pathPrefix, indexable);
325+
// by default we consider the complex object as an object mapping and process recursive mapping of every field just as ES would process based on
326+
// dynamic
327+
// mapping
328+
if (propertiesDefinitionMap.get(indexable.getName()) == null) {
329+
// Define mapping as object
330+
Map<String, Object> fieldDefinition = (Map<String, Object>) propertiesDefinitionMap.get(indexable.getName());
331+
if (fieldDefinition == null) {
332+
fieldDefinition = new HashMap<String, Object>();
333+
propertiesDefinitionMap.put(indexable.getName(), fieldDefinition);
334+
}
335+
objectFieldAnnotationParser.parseAnnotation(null, fieldDefinition, pathPrefix, indexable);
333336
}
334-
objectFieldAnnotationParser.parseAnnotation(null, fieldDefinition, pathPrefix, indexable);
335337
}
336338
}
337339

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public Class<?> getComponentType() {
5858
return getComponentType(0);
5959
}
6060

61+
public boolean isArrayOrCollection() {
62+
Class<?> type = getType();
63+
return type.isArray() || Collection.class.isAssignableFrom(type);
64+
}
65+
6166
public Class<?> getComponentType(int index) {
6267
Class<?> type = getType();
6368
if (type.isArray()) {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.alien4cloud</groupId>
55
<artifactId>elasticsearch-mapping-parent</artifactId>
6-
<version>1.6.0-SNAPSHOT</version>
6+
<version>1.5.1-SNAPSHOT</version>
77
<packaging>pom</packaging>
88

99
<name>Elastic search mapping parent</name>

0 commit comments

Comments
 (0)