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

相关推荐
csdn_wuwt8 小时前
前后端中Dto是什么意思?
开发语言·网络·后端·安全·前端框架·开发
JosieBook8 小时前
【Rust】 基于Rust 从零构建一个本地 RSS 阅读器
开发语言·后端·rust
努力的小郑12 小时前
今晚Cloudflare一哆嗦,我的加班计划全泡汤
前端·后端·程序员
百***618712 小时前
springboot整合mybatis-plus(保姆教学) 及搭建项目
spring boot·后端·mybatis
q***581912 小时前
Spring全家桶简介
java·后端·spring
武昌库里写JAVA12 小时前
微擎服务器配置要求,微擎云主机多少钱一年?
java·vue.js·spring boot·后端·sql
IUGEI12 小时前
深入解析HTTP长连接原理
java·网络·后端·网络协议·tcp/ip·http·https
q***555812 小时前
SpringBoot项目中替换指定版本的tomcat
spring boot·后端·tomcat
汤姆yu12 小时前
基于springboot的电脑商城系统
java·spring boot·后端
码事漫谈13 小时前
Visual Studio 2026真的值得升级吗中国开发者实测报告
后端