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

相关推荐
斌糖雪梨2 分钟前
spring registerBeanPostProcessors(beanFactory) 源码详解
java·后端·spring
wqww_121 分钟前
springboot 使用websocket来记录移动人物坐标
spring boot·后端·websocket
一只幸运猫.27 分钟前
Rust实用工具特型-Clone
开发语言·后端·rust
0xDevNull38 分钟前
Java BigDecimal 完全指南:从入门到精通
java·开发语言·后端
无心水43 分钟前
17、Java内存溢出(OOM)避坑指南:三个典型案例深度解析
java·开发语言·后端·python·架构·java.time·java时间处理
咚为1 小时前
深入浅出 Rust 内存顺序:从 CPU 重排到 Atomic Ordering
开发语言·后端·rust
weixin_408099672 小时前
OCR 在线识别 + API 接口实战:从网页验证到系统集成
图像处理·人工智能·后端·ocr·api·图片文字识别·文字识别
crack_comet2 小时前
Spring Boot 3.5.11 分离打包(无参数启动+Jar瘦身)完整配置文档
java·spring boot·后端·maven·intellij-idea·jar
echome8882 小时前
Go 语言并发编程:Channel 与 Goroutine 的完美结合
开发语言·后端·golang
weixin_408099672 小时前
身份证正反面合并+识别OCR接口调用
java·人工智能·后端·python·ocr·api·身份证ocr