我尝试使用Spring Data Elasticsearch创建一个示例项目,但由于path.home is not configured
错误而无法继续。我的弹性搜索版本 2.3.3 。我已经使用注释来创建bean,如下所示:
@Bean
public static NodeBuilder nodeBuilder() {
return new NodeBuilder();
}
@Bean
public ElasticsearchTemplate elasticsearchTemplate() {
return new ElasticsearchTemplate(getNodeClient());
}
@Bean
private static NodeClient getNodeClient() {
return (NodeClient) nodeBuilder().clusterName(UUID.randomUUID().toString()).local(true).node().client();
}
我的spring-data-elasticsearch版本:
我错过了什么吗?
答案 0 :(得分:0)
提供路径作为NodeBuilder的设置:
@Bean
public Settings elasticsearchSettings() {
Settings.Builder elasticsearchSettings = Settings.settingsBuilder()
.put("path.home", "/foo/bar");
return elasticsearchSettings.build();
}
@Bean
public ElasticsearchTemplate elasticsearchTemplate() {
return new ElasticsearchTemplate(NodeBuilder.nodeBuilder()
.settings(elasticsearchSettings()).node().client());
}
如果使用Spring Boot,this描述了.properties文件的用法:
spring.data.elasticsearch.properties.path.home=/foo/bar