@@ -216,6 +216,7 @@ private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
216
216
Field fieldAnnotation = property .findAnnotation (Field .class );
217
217
boolean isCompletionProperty = property .isCompletionProperty ();
218
218
boolean isNestedOrObjectProperty = isNestedOrObjectProperty (property );
219
+ DynamicMapping dynamicMapping = property .findAnnotation (DynamicMapping .class );
219
220
220
221
if (!isCompletionProperty && property .isEntity () && hasRelevantAnnotation (property )) {
221
222
@@ -230,7 +231,7 @@ private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
230
231
: null ;
231
232
232
233
mapEntity (builder , persistentEntity , false , property .getFieldName (), true , fieldAnnotation .type (),
233
- fieldAnnotation , property . findAnnotation ( DynamicMapping . class ) );
234
+ fieldAnnotation , dynamicMapping );
234
235
return ;
235
236
}
236
237
}
@@ -245,9 +246,9 @@ private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
245
246
if (isRootObject && fieldAnnotation != null && property .isIdProperty ()) {
246
247
applyDefaultIdFieldMapping (builder , property );
247
248
} else if (multiField != null ) {
248
- addMultiFieldMapping (builder , property , multiField , isNestedOrObjectProperty );
249
+ addMultiFieldMapping (builder , property , multiField , isNestedOrObjectProperty , dynamicMapping );
249
250
} else if (fieldAnnotation != null ) {
250
- addSingleFieldMapping (builder , property , fieldAnnotation , isNestedOrObjectProperty );
251
+ addSingleFieldMapping (builder , property , fieldAnnotation , isNestedOrObjectProperty , dynamicMapping );
251
252
}
252
253
}
253
254
@@ -328,7 +329,7 @@ private void applyDefaultIdFieldMapping(XContentBuilder builder, ElasticsearchPe
328
329
* @throws IOException
329
330
*/
330
331
private void addSingleFieldMapping (XContentBuilder builder , ElasticsearchPersistentProperty property ,
331
- Field annotation , boolean nestedOrObjectField ) throws IOException {
332
+ Field annotation , boolean nestedOrObjectField , @ Nullable DynamicMapping dynamicMapping ) throws IOException {
332
333
333
334
// build the property json, if empty skip it as this is no valid mapping
334
335
XContentBuilder propertyBuilder = jsonBuilder ().startObject ();
@@ -340,6 +341,11 @@ private void addSingleFieldMapping(XContentBuilder builder, ElasticsearchPersist
340
341
}
341
342
342
343
builder .startObject (property .getFieldName ());
344
+
345
+ if (nestedOrObjectField && dynamicMapping != null ) {
346
+ builder .field (TYPE_DYNAMIC , dynamicMapping .value ().name ().toLowerCase ());
347
+ }
348
+
343
349
addFieldMappingParameters (builder , annotation , nestedOrObjectField );
344
350
builder .endObject ();
345
351
}
@@ -380,10 +386,15 @@ private void addJoinFieldMapping(XContentBuilder builder, ElasticsearchPersisten
380
386
* @throws IOException
381
387
*/
382
388
private void addMultiFieldMapping (XContentBuilder builder , ElasticsearchPersistentProperty property ,
383
- MultiField annotation , boolean nestedOrObjectField ) throws IOException {
389
+ MultiField annotation , boolean nestedOrObjectField , @ Nullable DynamicMapping dynamicMapping ) throws IOException {
384
390
385
391
// main field
386
392
builder .startObject (property .getFieldName ());
393
+
394
+ if (nestedOrObjectField && dynamicMapping != null ) {
395
+ builder .field (TYPE_DYNAMIC , dynamicMapping .value ().name ().toLowerCase ());
396
+ }
397
+
387
398
addFieldMappingParameters (builder , annotation .mainField (), nestedOrObjectField );
388
399
389
400
// inner fields
0 commit comments