Java RestClient创建索引报错:java.net.SocketTimeoutException: 30,000 milliseconds timeo
theme: channing-cyan发生背景编写测试类准备创建索引库```import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;@SpringBootTestclass HotelAdminApplicationTests {private RestHighLevelClien...
·
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);
}
} ```
解决方案
改索引库名字:hotel->hotel_index
更多推荐
所有评论(0)