使用 Spring-Data Elasticsearch 和 @Document 动态创建索引名 [英] Creating Indexname Dynamically using Spring-Data Elasticsearch with @Document
本文介绍了使用 Spring-Data Elasticsearch 和 @Document 动态创建索引名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在
@Document(indexName="Something",type="type")
我尝试使用以下代码:
@Document(indexName="#{systemProperties['databaseName'] }", type = "dbtype")
但是在运行时,当我从 UI 发送两个请求以从不同索引的 ES 获取数据时,它无法正常工作.
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?
推荐答案
一种解决方法是使用 NativeSearchQuerries.在那里您可以将索引设置为您喜欢的任何内容:
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));
这篇关于使用 Spring-Data Elasticsearch 和 @Document 动态创建索引名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文