首页 > 解决方案 > NodeBuilder() 的替代方法是什么?它似乎已被弃用,我正在努力在 spring 数据中配置 Elasticsearch

问题描述

这就是我的代码目前的样子。这是我加载elasticsearch时需要的配置文件。

public class Elastic_config {

        @Bean
        NodeBuilder nodebuilder(){
            return new NodeBuilder().Node();
        }

        @Bean
        ElasticsearchTemplate elasticsearchOperations() throws IOException {
            File tempFile = File.createTempFile("temp-elastic", Long.toString(System.nanoTime()));

        Settings.Builder elasticsearchSettings =
                Settings.settingsBuilder()
                        .put("http.enabled","true")
                        .put("index.number_of_shards", "1")
                        .put("path.data", new File(tempFile, "data").getAbsolutePath())
                        .put("path.logs", new File(tempFile, "logs").getAbsolutePath())
                        .put("path.work", new File(tempFile, "work").getAbsolutePath())
                        .put("path.home", tempFile);

        return new ElasticsearchTemplate(nodeBuilder())
                .local(true)
                .settings(elasticsearchSettings.build())
                .node()
                .client();
        }
}

标签: springspring-dataspring-data-elasticsearch

解决方案


我使用了传输客户端来代替它。见链接 https://www.baeldung.com/spring-data-elasticsearch-tutorial


推荐阅读