这就是我的代码目前的样子。这是我加载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();
}
}
我使用了运输客户端而不是工作。见链接https://www.baeldung.com/spring-data-elasticsearch-tutorial