Search code examples
javaspringelasticsearchspring-data-elasticsearch

Elastic Search mapping on Java Spring startup


I'm using spring data elastic search and i'm having a document that i want to store. I'm wondering, is there a way on the microservice starts to automatically send to elastic search the mapping for this document? I have the repository defined and currently when i start the service, there is no mapping added to the elastic search.


Solution

  • Each entity should have @Document annotation on class level, and for activating index auto-creation during bootstrapping there is argument createIndex for this annotation. When this argument is set to true - an index will be automatically created.

    For improving index settings during creation, there is a separate annotation @Setting

    More details can be found here

    Actual index mapping is created based on entity’s field annotations (like @Field, @Id etc).

    Here is more info about available entity annotations