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

相关推荐
林小帅14 分钟前
NestJS v11 + Prisma v7 ESM 迁移配置解析
前端·javascript·后端
IT_陈寒29 分钟前
React的setState竟然不是立刻生效的,害我调试半天
前端·人工智能·后端
逝水无殇2 小时前
C# 字符串(String)详解
开发语言·后端·c#
神奇小汤圆2 小时前
牛客网Java八股文|2026秋招面试题汇总(金九银十冲刺专用)
后端
cfm_29142 小时前
SpringBoot MockMvc
spring boot·后端·log4j
神奇小汤圆3 小时前
你的Java天花板,不是Spring Boot,是思维方式
后端
梨子同志3 小时前
Maven
后端
用户41659673693553 小时前
堡垒机 Web CLI 部署教程
后端
xiyueyezibile3 小时前
“自迭代” Skill 的 team-pitfalls 的演进
前端·后端·ai编程
叫我少年3 小时前
C# StringBuilder 基础入门
后端