问题
I am trying to get indexname
dynamically in
@Document(indexName="Something",type="type")
I have tried using below code:
@Document(indexName="#{systemProperties['databaseName'] }", type = "dbtype")
but at runtime when I am sending two request from UI to get the data from ES from different indexes,it is not working properly.
what should I do to solve this issue?
回答1:
A workaround is, to work with NativeSearchQuerries. There you can set the index to whatever you like:
NativeSearchQuery query = new NativeSearchQueryBuilder().withIndices(indexName)
.withQuery(QueryBuilders.matchPhraseQuery("_all", request.getSearchTerm().getSearchString()))
.withPageable(new PageRequest(request.getPaging(), request.getMaxResults()))
....
.build();
result =elastic.query(query, query->query2Result(query));
来源:https://stackoverflow.com/questions/38097197/creating-indexname-dynamically-using-spring-data-elasticsearch-with-document