Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicMapping annotation should be applicable to any object field. #1767

Closed
TEXHIK opened this issue Apr 9, 2021 · 5 comments · Fixed by #1779
Closed

DynamicMapping annotation should be applicable to any object field. #1767

TEXHIK opened this issue Apr 9, 2021 · 5 comments · Fixed by #1779
Labels
type: bug A general bug

Comments

@TEXHIK
Copy link

TEXHIK commented Apr 9, 2021

As of the documentation, it is possible to make different values for dynamicMapping setting in document and it's inner objects.
However, it is not possible to enable dynamicMapping for @Field(type = FieldType.Object), because it is not an entity.
There should be a way to apply this setting on any property, not only for documents, as there many cases, when Object field is not an entity - Map, for example.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 9, 2021
@sothawo sothawo removed the status: waiting-for-triage An issue we've not yet triaged label Apr 9, 2021
@sothawo
Copy link
Collaborator

sothawo commented Apr 9, 2021

@sothawo sothawo closed this as completed Apr 9, 2021
@TEXHIK
Copy link
Author

TEXHIK commented Apr 11, 2021

I tried, but it is completely ignored, property just mapped as { "type": "object"} without any other settings. There is a check if the property is an entity, and if not - dynamic mapping not applied, and o check for annotation is done in that case.
P.S. My property is a map, not a class.

@sothawo
Copy link
Collaborator

sothawo commented Apr 12, 2021

Can you provide the entity definition for your case so that this can be reproduced?

@sothawo sothawo reopened this Apr 12, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 12, 2021
@sothawo sothawo added the status: waiting-for-feedback We need additional information before we can continue label Apr 12, 2021
@TEXHIK
Copy link
Author

TEXHIK commented Apr 13, 2021

Here is my Field in code:

@Field(type = FieldType.Object)
@DynamicMapping(DynamicMappingValue.True)
private Map<String, Object> body;

This is field in elastic:

"body": {
    "type": "object"
},

And this is a check in MappingBuilder:220

if (!isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {

	if (fieldAnnotation == null) {
		return;
	}

	if (isNestedOrObjectProperty) {
		Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
		ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
				? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
				: null;

		mapEntity(builder, persistentEntity, false, property.getFieldName(), true, fieldAnnotation.type(),
				fieldAnnotation, property.findAnnotation(DynamicMapping.class));
		return;
	}
}

So as you can see, nothing Object-related applied at all, if the property isn't an entity. But it isn't.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 13, 2021
@sothawo sothawo added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Apr 14, 2021
@sothawo sothawo changed the title DynamicMapping annotation should be applieable to any object field, even if it is not an entity DynamicMapping annotation should be applicable to any object field. Apr 17, 2021
sothawo added a commit that referenced this issue Apr 17, 2021
@sothawo sothawo added this to the 4.3 M1 (2021.1.0) milestone Apr 17, 2021
sothawo added a commit that referenced this issue Apr 17, 2021
sothawo added a commit that referenced this issue Apr 17, 2021
sothawo added a commit that referenced this issue Apr 17, 2021
@sothawo
Copy link
Collaborator

sothawo commented Apr 17, 2021

fixed in master an backported to 4.2.x, 4.1.x and 4.0.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
3 participants