spring boot3整合Elasticsearch 实现快速入门
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
@SpringBootApplication
public class ElasticsearchApplication extends AbstractElasticsearchConfiguration {
@Override
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200") // 替换为你的Elasticsearch节点地址
.build();
return RestClients.create(clientConfiguration).rest();
}
public static void main(String[] args) {
SpringApplication.run(ElasticsearchApplication.class, args);
}
}
这段代码展示了如何在Spring Boot 3应用程序中整合Elasticsearch,并创建一个RestHighLevelClient
实例用于连接到Elasticsearch服务。注意替换localhost:9200
为你的Elasticsearch节点地址。
评论已关闭