Creating Indexname Dynamically using Spring-Data Elasticsearch with @Document

大城市里の小女人 提交于 2021-02-07 20:14:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!