Skip to content

Use a customized typehint attribute name #2029

Closed
@jinwg

Description

@jinwg

is there any way to customize the default type hit attributes filed?

	String DEFAULT_TYPE_KEY = "_class";

Activity

sothawo

sothawo commented on Dec 16, 2021

@sothawo
Collaborator

This is not possible at the moment. What would be the use case to have a customized name for this field name, which is a field internally by Spring Data Elasticsearch ?

jinwg

jinwg commented on Dec 16, 2021

@jinwg
Author

i am working on a search only project which need to read a big index stores more than 10 years data. we already have a filed play similar document type role. it is really a overkill for me to re-index all old documents to add the new filed. either a customized filed name or a callback hook could create sub-classes both works for my case, but neither of them are available in current release.

changed the title [-]Use a customized typehit attribute name[/-] [+]Use a customized typehint attribute name[/+] on Dec 17, 2021
sothawo

sothawo commented on Dec 17, 2021

@sothawo
Collaborator

So you have an index that contains documents that correspond to different entity classes in your application, and you have a field in your index that contains the full qualified name of the respective class? Do this classes have a common base class that you will use in Spring Data Elasticsearch as entity class when reading the data?

One thing to solve this would be to allow the configuration of the type hint field name as you suggest. A better way would be to have a lifecycle callback that is invoked after the data has been read from Elasticsearch and before it is mapped into an entity. In this callback you could add a _class field that contains the value of your field that has the class name.

There is an open issue to add that callback (#2009).

jinwg

jinwg commented on Dec 17, 2021

@jinwg
Author

@sothawo, yes we have a base entity class. i am using mapstruct with customized converter function to do this right now. but i think it will be great to have the native feature in this library.

added
status: blockedAn issue that's blocked on an external project change
and removed on Dec 19, 2021

7 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Use a customized typehint attribute name · Issue #2029 · spring-projects/spring-data-elasticsearch