Sachin Sachin - 6 months ago 89
Java Question

How to set the annotation properties in spring data Elasticsearch

I've a question in spring data elasticsearch.I would like to know how whether we can set the annotation values of @Document annotation from a properties file or set it dynamically.

For eg :-

@Document(indexName = "myindex",type="mytype")
public class DocumentModel {

Here,I want to set the values of this annotation from a .properties file or use some setter methods for the same instead of hard coding it. Is there any proper way to do this ? Please help!


If you're using elasticsearchTemplate, there is a simpler variant, you can do it like this:

IndexQuery indexQuery = new IndexQueryBuilder()

the call to withIndex("...") will override whatever index name you have in the @Document annotation