写在前面:
继续记录自己的SpringBoot学习之旅,这次是SpringBoot应用相关知识学习记录。若看不懂则建议先看前几篇博客,详细代码可在我的Gitee仓库SpringBoot克隆下载学习使用!
![![[Pasted image 20220831113450.png]]](https://1000bd.com/contentImg/2024/04/20/c48ecd90b144d1b8.png)
localhost:9200,出现如图即可成功![![[Pasted image 20220831113528.png]]](https://1000bd.com/contentImg/2024/04/20/fd40746d5ab988b0.png)
![![[Pasted image 20220831150028.png]]](https://1000bd.com/contentImg/2024/04/20/77ad562b6e542f73.png)
{
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "ik_max_word",
"copy_to": "all"
},
"password": {
"type": "text",
"analyzer": "ik_max_word",
"copy_to": "all"
},
"age": {
"type": "keyword"
},
"all": {
"type":"text",
"analyzer":"ik_max_word"
}
}
}
}
![![[Pasted image 20220831150227.png]]](https://1000bd.com/contentImg/2024/04/20/4c145f1830a8ea5b.png)

![![[Pasted image 20220831153523.png]]](https://1000bd.com/contentImg/2024/04/20/9692b10378ad5e4b.png)
xxx/ _ doc/id格式![![[Pasted image 20220831154314.png]]](https://1000bd.com/contentImg/2024/04/20/a22c2fa242590cda.png)
![![[Pasted image 20220831154914.png]]](https://1000bd.com/contentImg/2024/04/20/1489435482aad1ea.png)
![![[Pasted image 20220831162633.png]]](https://1000bd.com/contentImg/2024/04/20/8ba456ca1ebd2884.png)
![![[Pasted image 20220831174627.png]]](https://1000bd.com/contentImg/2024/04/20/1754f1ea42f634d6.png)
private RestHighLevelClient client;
@Test
void createIndex() throws IOException {
HttpHost host = HttpHost.create("http://localhost:9200");;
RestClientBuilder builder = RestClient.builder(host);
client = new RestHighLevelClient(builder);
// 客户端操作
CreateIndexRequest request = new CreateIndexRequest("users");
client.indices().create(request, RequestOptions.DEFAULT);
// 关闭客户端
client.close();
}
// 创建文档
@Test
public void addESDoc() throws IOException {
IndexRequest indexRequest = new IndexRequest("users").id("1");
String json = "{\n" +
" \"name\": \"大家\",\n" +
" \"password\": \"早上好大家\",\n" +
" \"age\": 23\n" +
"}";
indexRequest.source(json,XContentType.JSON);
client.index(indexRequest,RequestOptions.DEFAULT);
}
其它具体详见Gitee上的项目