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

相关推荐
间彧28 分钟前
CAP定理:Partition tolerance(分区容错性)详解
后端
Python私教1 小时前
PyQt:用 Python 打造原生级桌面应用的强大框架
后端
Python私教1 小时前
用 PyQt 开发一个桌面计算器:从零到完整实战指南
后端
Mos_x1 小时前
Spring 中的 @ExceptionHandler 注解详解与应用
java·后端
爆爆凯1 小时前
Spring Boot Web上下文工具类详解:获取Request、Response和参数
前端·spring boot·后端
IT_陈寒1 小时前
7个Java Stream API的隐藏技巧,让你的代码效率提升50%
前端·人工智能·后端
绝无仅有2 小时前
大厂深度面试相关文章:深入探讨底层原理与高性能优化
后端·面试·架构
绝无仅有2 小时前
大厂真实面试指南:解答核心问题与技术深度探讨
后端·面试·架构
JaguarJack2 小时前
PHP 现代特性速查 写出更简洁安全的代码(中篇)
后端·php
Victor3563 小时前
Redis(104)Redis的最大数据量是多少?
后端