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

相关推荐
alonewolf_9923 分钟前
深入Spring核心原理:从Bean生命周期到AOP动态代理全解析
java·后端·spring
Justin3go7 小时前
HUNT0 上线了——尽早发布,尽早发现
前端·后端·程序员
Tony Bai7 小时前
高并发后端:坚守 Go,还是拥抱 Rust?
开发语言·后端·golang·rust
一线大码8 小时前
SpringBoot 3 和 4 的版本新特性和升级要点
java·spring boot·后端
weixin_425023008 小时前
Spring Boot 配置文件优先级详解
spring boot·后端·python
weixin_425023008 小时前
Spring Boot 实用核心技巧汇总:日期格式化、线程管控、MCP服务、AOP进阶等
java·spring boot·后端
一线大码8 小时前
Java 8-25 各个版本新特性总结
java·后端
VX:Fegn08959 小时前
计算机毕业设计|基于springboot + vue校园社团管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·后端·课程设计
To Be Clean Coder9 小时前
【Spring源码】通过 Bean 工厂获取 Bean 的过程
java·后端·spring
weixin1997010801610 小时前
闲鱼 item_get - 商品详情接口对接全攻略:从入门到精通
java·后端·spring