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

相关推荐
ServBay25 分钟前
AI 做的小工具,怎样交给同事用?
后端·aigc·ai编程
用户693717500138433 分钟前
AI 越强,为什么我们反而越来越担心失业?
前端·后端·github
咖啡八杯2 小时前
LoginUser 适配器模式:适配 SysUser 到 UserDetails
java·开发语言·后端·框架·适配器模式·若依
拖孩3 小时前
又又又用 AI 写了个小程序:我站起来猛蹬 AI,使劲薅羊毛
前端·后端·微信小程序
北冥有鱼3 小时前
从 bean::method 里抠出注解:Java 方法引用元数据反查全记录
java·后端
CoderYanger4 小时前
Java EE 进阶:11. SpringBoot 统一功能处理(第四弹):@ControllerAdvice 源码分析+案例代码
java·数据库·spring boot·后端·spring·java-ee·mybatis
Sailing4 小时前
🔥🔥sql: waiting for connection 踩坑:不要一味调大 MaxOpenConns
后端·go·gin
一条Go6 小时前
ent + PostgreSQL:部分唯一索引怎么表达「全表最多一个」
后端·github
陈随易7 小时前
MoonBit 2026 深圳线下交流分享
前端·后端·程序员
HarmonSir8 小时前
Octop 架构解析(外番篇):两种多 Agent 协作,Octop 群聊房间 vs dsh 工单授权
后端·架构