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.9k stars 1.33k forks source link

Allow to customize the mapped type name for @InnerField and @Field annotations #2950

Closed reta closed 1 month ago

reta commented 1 month ago

In Spring Data OpenSearch [1], which is built on top of Spring Data Elasticsearch, we are running into cases where both projects differ in incompatible ways. One of such cases is supported mapping field types (baked by org.springframework.data.elasticsearch.annotations.FieldType), for example:

Flattened("flattened"), //

would have to become

Flat_Object("flat_oblect"), //

for OpenSearch.

This pull request adds optional mappedName attribute to @InnerField and@Field annotations (and model classes respectively), to address the possible divergence, for example:

@Field(type = FieldType.Flattened, mappedName = "flat_oblect") String flattenedField;

It would require a bit more work for OpenSearch users but not the Elasticsearch ones. The change would be non-breaking (defaults to "" and FieldType::getMappedType) and work seamlessly.

Closes https://github.com/spring-projects/spring-data-elasticsearch/issues/2942

reta commented 1 month ago

@sothawo would really appreciate a review when you have some time, thank you

sothawo commented 1 month ago

tomorrow, been busy this week 😁

reta commented 1 month ago

Thanks for the PR, I just think that the mappedName should be called mappedTypeName so that it will not be confused with the field name, that is mapped as well from the Java property name to the Field.name attribute

Thanks a lot for the review @sothawo , comments addressed! Thanks again!