【问题标题】:Creating Indexname Dynamically using Spring-Data Elasticsearch with @Document使用带有@Document 的 Spring-Data Elasticsearch 动态创建索引名
【发布时间】:2016-11-01 00:28:33
【问题描述】:

我正在尝试在

中动态获取indexname
@Document(indexName="Something",type="type")

我尝试过使用以下代码:

@Document(indexName="#{systemProperties['databaseName'] }", type = "dbtype")

但在运行时,当我从 UI 发送两个请求以从不同索引的 ES 获取数据时,它无法正常工作。

我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: spring spring-security spring-boot spring-data spring-data-elasticsearch


    【解决方案1】:

    一种解决方法是使用 NativeSearchQuerries。 在那里您可以将索引设置为您喜欢的任何内容:

    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));
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-17
    • 2021-11-03
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 2014-04-15
    相关资源
    最近更新 更多