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

相关推荐
IT枫斗者枫哥8 分钟前
UPDATE影响0行,接口却返回成功:把版本冲突接回业务
java·后端
一帅29 分钟前
Muzzle:给 Java Agent 戴上的"安全口罩"
后端
Bazingga34 分钟前
从0到1吃透Function Calling:Spring AI完整实战
后端
写了20年代码的老程序员36 分钟前
想让 AI 改 Bug 快准狠?先给日志加个业务代码坐标
java·后端·apache log4j
据说幸运很容易36 分钟前
从 Run 到 Report:现有框架引入 Allure 的实践
后端·架构
合橱瑰43 分钟前
踩坑实录:子进程“假 Ready”导致窗口永远无法唤起?
后端·全栈
imDwAaY44 分钟前
如何快速定位线上OOM
后端
一帅44 分钟前
大象无形:OTel Java Agent 的隐身哲学
后端
dd聊技术1 小时前
给项目接上动态线程池
后端
hsfxuebao1 小时前
常用开源项目github
后端·github