
不是你的问题,是SpringBoot的问题,它不支持最新的elasticsearch,它虽然会报错但是能正常保存到elasticsearch中,把它放在try中就好了。
- @Test //创建文档
- void createDoc() {
- IndexRequest request = new IndexRequest("books").id("9");
- //把写在body中的json写在这里
- String json="{\"name\":\"李义新999\",\"type\":\"person\",\"description\":\"很棒\"}";
- request.source(json, XContentType.JSON);
- try{
- client.index(request, RequestOptions.DEFAULT);
- }catch(IOException e){
- }
- }