Java RestClient创建索引报错:java.net.SocketTimeoutException: 30,000 milliseconds timeo

发生背景

编写测试类准备创建索引库

java 复制代码
import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;

@SpringBootTest
class HotelAdminApplicationTests {

    private RestHighLevelClient client;

    @BeforeEach
    void setUp(){
        this.client = new RestHighLevelClient(RestClient.builder(
                HttpHost.create("http://127.0.0.1:9200")
        ));
    }

    @AfterEach
    void tearDown() throws IOException {
        this.client.close();
    }

    @Test
    void contextLoads() {
        System.out.println(client);
    }

    @Test
    void createHotelIndex() throws IOException {
        // 创建Request对象
        CreateIndexRequest request = new CreateIndexRequest("hotel");
        // 准备请求的参数:DSL
        request.source(MAPPING_TEMPLATE, XContentType.JSON);
        // 发送请求
        client.indices().create(request, RequestOptions.DEFAULT);
    }

}

解决方案

改索引库名字:hotel->hotel_index

相关推荐
Billow_lamb17 分钟前
Spring Boot2.x.x 全局错误处理
java·spring boot·后端
苏三的开发日记18 分钟前
Java后台定时器导致系统奔溃的原因分析
后端
remaindertime20 分钟前
基于Ollama和Spring AI:实现本地大模型对话与 RAG 功能
人工智能·后端·ai编程
Lear20 分钟前
Spring Boot异步任务实战:优化耗时操作,提升系统性能
后端
望眼欲穿的程序猿1 小时前
Win系统Vscode+CoNan+Cmake实现调试与构建
c语言·c++·后端
bing_1581 小时前
Spring Boot 项目中判断集合(List、Set、Map)不能为空且不为 null的注解使用
spring boot·后端·list
喵个咪1 小时前
Go 接口与代码复用:替代继承的设计哲学
后端·go
喵个咪1 小时前
ASIO 定时器完全指南:类型解析、API 用法与实战示例
c++·后端
IT_陈寒2 小时前
Vite 3.0 重磅升级:5个你必须掌握的优化技巧和实战应用
前端·人工智能·后端
gadiaola2 小时前
【计算机网络面试篇】HTTP
java·后端·网络协议·计算机网络·http·面试