spring-projects / spring-data-elasticsearch

Provide support to increase developer productivity in Java when using Elasticsearch. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-elasticsearch/
Apache License 2.0
2.91k stars 1.33k forks source link

Field mapping with underscore causes runtime exceptions [DATAES-419] #992

Closed spring-projects-issues closed 5 years ago

spring-projects-issues commented 6 years ago

Aram Mirzadeh opened DATAES-419 and commented

I have a working env ... Java 8, Boot 2.0.0.M7, Data 3.0.2.RELEASE, Cluster is a remote 3 node, ES 5.6.4 (xpack disabled)

{{ @Id private String id; private String firstName; private String lastName;}}

Methods like:

findByFirstName and findByLastName both work if I leave it as is ... however, the incoming json (produced by another system) has an underscore in the field names, ex: first_name, last_name.

I added a @JsonProperty("first_name") to the model class, the inserts/mappings do work with the new field name, however any combination of findByFirstName, findByFirst_Name, findByFirstName, findByFirstName all result in a runtime exception.

{{ @Id private String id; @JsonProperty("first_name") private String firstName; private String lastName;}}

In this test project I don't have a ES client method, it's all @EnableAutoConfiguration and two lines in the application.properties file (spring.data.elasticsearch.cluster-nodes, cluster-name)

First, what is the proper method name creation to automap this? Second, is there anyway of catching the query that is being built via the auto query builder so this can be debugged locally?

Thanks


Affects: 3.0.2 (Kay SR2)

1 votes, 4 watchers

spring-projects-issues commented 6 years ago

Sungo Fan commented

I have also encounter this problem. do you have any update or work around? thanks

spring-projects-issues commented 5 years ago

akhtyamovrr commented

Hello

Are there any plans to fix the issue? It breaks compatibility of old data with newer versions of the framework that causes additional efforts for data migration and code changes of other components during an update to the latest release version. Because of these reasons update of dependencies becomes impossible for some consumers

spring-projects-issues commented 5 years ago

sothawo commented

Is this still an issue with a RuntimeException? There are several tickets concerning the mapping with @JsonProperty annotated values, but they don't mention runtime exceptions

spring-projects-issues commented 5 years ago

Aram Mirzadeh commented

sothawo - I don't think I have run across since 2.0.0

spring-projects-issues commented 5 years ago

sothawo commented

error did not occur again, and DATAES-562 now is the correct way to handle custom field name mapping