Skip to content

@ScriptedFields & Kotlin data classes [DATAES-915] #1488

Closed
@spring-projects-issues

Description

@spring-projects-issues

Alfonso Gonzalez Luis opened DATAES-915 and commented

I found that when I have a document that looks like, this:

 

@Document(indexName = "test")
data class Test(
 @Id var id: String
 @ScriptedField var distance: Double
)

 

and try to make a search like

 

elasticsearchOperations.search(search, Test.class)

 

the conversion fails on

MappingElasticsearchConverter#readEntity

because it tries to instantiate the target entity without all the required parameters.

Looking further into the code, I saw that it tries to add the script_fields later on, with  the populateScriptFields method, but only if this condition is not met, which led me to modify my class to look like this

@Document(indexName = "test")
data class Test(@Id var id: String) {
 @ScriptedField val distance: Double
}

 

Since this is an issue that can occur both in Kotlin & Java, I think having some documentation of this would be great. It could help other people that might get into the same issue I did.

The other solution could be to combine the fields of the Document with the source and let ElasticsearchPropertyValueProvider handle all of it. But that one requires much more work.

 

 


Affects: 4.0.3 (Neumann SR3)

Metadata

Metadata

Assignees

Labels

in: mappingMapping and conversion infrastructuretype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions