测试所需要的方法,例如 crud,批处理等
@SpringBootTestclass YueEsApiApplicationTests {@Autowired@Qualifier("restHighLevelClient")private RestHighLevelClient client;@Testvoid contextLoads() {}//测试索引的创建 Request PUT kuang_index@Testvoid testCreateIndex() throws IOException {//1. 创建索引请求CreateIndexRequest request = new CreateIndexRequest("yue_index");//2. 客户端执行创建请求 IndicesClient 请求后获得响应CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);System.out.println(createIndexResponse);}//测试获取索引 判断其是否存在@Testvoid testExists() throws IOException {GetIndexRequest request = new GetIndexRequest("yue_index");boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);System.out.println(exists);}//测试删除索引@Testvoid testDeleteIndex() throws IOException {DeleteIndexRequest request = new DeleteIndexRequest("yue_index");//删除AcknowledgedResponse delete = client.indices().delete(request, RequestOptions.DEFAULT);System.out.println(delete.isAcknowledged());}//测试添加文档@Testvoid testAddDocument() throws IOException {//创建对象User user = new User("aa", 3);//创建请求IndexRequest request = new IndexRequest("yue_index");//规则 put /kuang_index/_doc/1request.id("1");request.timeout(TimeValue.timeValueSeconds(1));request.timeout("1s");//将我们的数据放入请求 jsonrequest.source(JSON.toJSONString(user), XContentType.JSON);//客户端发送请求,获取响应的结果IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);System.out.println(indexResponse.toString());//对应我们命令返回的状态 CREATEDSystem.out.println(indexResponse.status());}//获取文档,判断是否存在@Testvoid testIsExists() throws IOException {GetRequest request = new GetRequest("yue_index", "1");//不获取返回的 _source 的上下文了request.fetchSourceContext(new FetchSourceContext(false));request.storedFields("_none_");boolean exists = client.exists(request, RequestOptions.DEFAULT);System.out.println(exists);}//获得文档的信息@Testvoid testGetDocument() throws IOException {GetRequest request = new GetRequest("yue_index", "1");GetResponse response = client.get(request, RequestOptions.DEFAULT);//打印文档的内容System.out.println(response.getSourceAsString());//返回的全部内容和命令是一样的System.out.println(response);}//更新文档的信息@Testvoid testUpdateDocument() throws IOException {UpdateRequest request = new UpdateRequest("yue_index", "1");request.timeout("1s");User user = new User("狂神说Java", 18);request.doc(JSON.toJSONString(user), XContentType.JSON);UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);System.out.println(updateResponse.status());}//删除文档的记录@Testvoid testdeleteDocument() throws IOException {DeleteRequest request = new DeleteRequest("yue_index", "1");request.timeout("1s");DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);System.out.println(deleteResponse.status());}//特殊的,真实项目一般都会批量插入数据@Testvoid testBulkRequest() throws IOException {BulkRequest bulkRequest = new BulkRequest();bulkRequest.timeout("10s");List
- macOS 中如何将 Control 和 Command 键互换?
- vue - vue中的process.env.NODE_ENV和环境变量
- Vue 项目搭建流程和使用大全
- ClickHouse CTO空降中国开发者和用户沙龙
- Go中append和链表的关系
- 祁唯羿,于炀和祁醉为什么分手
- 与人沟通的技巧和方法有哪些,与人沟通的技巧有哪些
- 曹操让官位:是和袁绍玩一场猫捉老鼠游戏
- 专治太监和宫女的满清十大酷刑
- 揭秘:历史上唐玄宗和杨贵妃的爱情其实并不是真爱