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

[FEATURE PROPOSAL] Allow to customize the mapped type for @InnerField and @Field annotations #2942

Closed reta closed 1 month ago

reta commented 2 months 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.

One of the simplest (but no necessarily good) ways to support Elasticsearch and OpenSearch is to maintain the union of both (Flattened and Flat_Object): solves the problem but adds confusion.

One of (arguably) better alternatives is to add 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.

@sothawo I am wondering if you (or/and other maintainers) would be open to accept such feature proposal (I will be taking care of all the necessary work if greenlighted).

Thank you!

[1] https://github.com/opensearch-project/spring-data-opensearch

sothawo commented 2 months ago

Hi, sure, provide a PR for this.

reta commented 1 month ago

(just for the record, it is just a coincidence but I am off next week, will pick this issue once back)