theme: channing-cyan

发生背景

编写测试类准备创建索引库

``` 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);
}

} ```

CK(~FYM`R0Q~I%7)WUHP{@E.png

解决方案

改索引库名字:hotel->hotel_index

V}{2778[~E{}]%$OXLYPW_C.png

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐