@@ -215,6 +215,7 @@ private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
215215 Field fieldAnnotation = property .findAnnotation (Field .class );
216216 boolean isCompletionProperty = isCompletionProperty (property );
217217 boolean isNestedOrObjectProperty = isNestedOrObjectProperty (property );
218+ DynamicMapping dynamicMapping = property .findAnnotation (DynamicMapping .class );
218219
219220 if (!isCompletionProperty && property .isEntity () && hasRelevantAnnotation (property )) {
220221
@@ -228,8 +229,8 @@ private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
228229 ? elasticsearchConverter .getMappingContext ().getPersistentEntity (iterator .next ())
229230 : null ;
230231
231- mapEntity (builder , persistentEntity , false , property .getFieldName (), isNestedOrObjectProperty ,
232- fieldAnnotation . type (), fieldAnnotation , property . findAnnotation ( DynamicMapping . class ) );
232+ mapEntity (builder , persistentEntity , false , property .getFieldName (), isNestedOrObjectProperty , fieldAnnotation . type (),
233+ fieldAnnotation , dynamicMapping );
233234 return ;
234235 }
235236 }
@@ -244,9 +245,9 @@ private void buildPropertyMapping(XContentBuilder builder, boolean isRootObject,
244245 if (isRootObject && fieldAnnotation != null && property .isIdProperty ()) {
245246 applyDefaultIdFieldMapping (builder , property );
246247 } else if (multiField != null ) {
247- addMultiFieldMapping (builder , property , multiField , isNestedOrObjectProperty );
248+ addMultiFieldMapping (builder , property , multiField , isNestedOrObjectProperty , dynamicMapping );
248249 } else if (fieldAnnotation != null ) {
249- addSingleFieldMapping (builder , property , fieldAnnotation , isNestedOrObjectProperty );
250+ addSingleFieldMapping (builder , property , fieldAnnotation , isNestedOrObjectProperty , dynamicMapping );
250251 }
251252 }
252253
@@ -320,7 +321,7 @@ private void applyDefaultIdFieldMapping(XContentBuilder builder, ElasticsearchPe
320321 * @throws IOException
321322 */
322323 private void addSingleFieldMapping (XContentBuilder builder , ElasticsearchPersistentProperty property ,
323- Field annotation , boolean nestedOrObjectField ) throws IOException {
324+ Field annotation , boolean nestedOrObjectField , @ Nullable DynamicMapping dynamicMapping ) throws IOException {
324325
325326 // build the property json, if empty skip it as this is no valid mapping
326327 XContentBuilder propertyBuilder = jsonBuilder ().startObject ();
@@ -332,6 +333,11 @@ private void addSingleFieldMapping(XContentBuilder builder, ElasticsearchPersist
332333 }
333334
334335 builder .startObject (property .getFieldName ());
336+
337+ if (nestedOrObjectField && dynamicMapping != null ) {
338+ builder .field (TYPE_DYNAMIC , dynamicMapping .value ().name ().toLowerCase ());
339+ }
340+
335341 addFieldMappingParameters (builder , annotation , nestedOrObjectField );
336342 builder .endObject ();
337343 }
@@ -342,10 +348,15 @@ private void addSingleFieldMapping(XContentBuilder builder, ElasticsearchPersist
342348 * @throws IOException
343349 */
344350 private void addMultiFieldMapping (XContentBuilder builder , ElasticsearchPersistentProperty property ,
345- MultiField annotation , boolean nestedOrObjectField ) throws IOException {
351+ MultiField annotation , boolean nestedOrObjectField , @ Nullable DynamicMapping dynamicMapping ) throws IOException {
346352
347353 // main field
348354 builder .startObject (property .getFieldName ());
355+
356+ if (nestedOrObjectField && dynamicMapping != null ) {
357+ builder .field (TYPE_DYNAMIC , dynamicMapping .value ().name ().toLowerCase ());
358+ }
359+
349360 addFieldMappingParameters (builder , annotation .mainField (), nestedOrObjectField );
350361
351362 // inner fields
0 commit comments