2

Is it possible avoid the indexName in document annotation? Because I have dynamic indexName so I cannot define it previously

2
  • Leaving aside Spring and its template, what actually do you want to achieve at Elasticsearch side? What does update any of those dynamically created indices with info to Elasticsearch mean? Commented Feb 1, 2018 at 15:35
  • I use the ElasticsearchTemplate to create indices dynamically. I have a model which contains the Document annotation and I want to use it to update info using different indices, so I need to modify the indexName dynamically of the model to that purpose. Commented Feb 1, 2018 at 17:16

1 Answer 1

-1

According to this issue and the related PR, you can use a SpEL expression in the indexName attribute of the @Document annotation:

@Document(indexName = "#{@somePrefix}-index", type = "sometype")

where you also have a bean like the one below defined in your context

<bean id="somePrefix" class="java.lang.String">
    <constructor-arg value="${env}-myapp"/>
</bean>

So in your case, you could have a bean which contains a mutable index name that is then used to create/search the new indices.

Sign up to request clarification or add additional context in comments.

6 Comments

So how can I modify the bean value from a Java method?
May the bright mind who downvoted care to explain why so all the community benefits from his wisdom ;-)
@CarlosVázquezLosada You probably should show some code so we better see what you're willing to achieve
Yo @Val I have created a new question, because this one is not mine so I couldn't paste my own code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.