1
2
3
4
5
6
7
8
9
10
11
12
|
POST /alias_users/_doc
{
"age": 18,
"weight": 50.0,
"info": "曾州市第一中学高三一班张薛",
"email": "zhangxue@163.com",
"score": [92.1, 93.2],
"name": {
"firstName": "薛",
"lastName": "张"
}
}
|
// 响应结果
{
"_index": "users",
"_id": "orl0ZZEBrAuQs0dUWDfg",
"_version": 1,
"result": "created",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
|
POST /alias_users/_doc/2
{
"age": 17,
"weight": 52.4,
"isMarried": true,
"info": "曾州市第一中学高三一班薛高",
"email": "zhangxue@163.com",
"score": [96.1, 91.2],
"name": {
"firstName": "高",
"lastName": "薛"
}
}
|
// 响应结果
{
"_index": "users",
"_id": "2",
"_version": 1,
"result": "created",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
1
|
GET /alias_users/_doc/orl0ZZEBrAuQs0dUWDfg
|
// 响应结果
{
"_index": "users",
"_id": "orl0ZZEBrAuQs0dUWDfg",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"age": 18,
"weight": 50,
"info": "曾州市第一中学高三一班张薛",
"email": "zhangxue@163.com",
"score": [
92.1,
93.2
],
"name": {
"firstName": "薛",
"lastName": "张"
}
}
}
1
|
GET /alias_users/_doc/2
|
// 响应结果
{
"_index": "users",
"_id": "2",
"_version": 1,
"_seq_no": 1,
"_primary_term": 1,
"found": true,
"_source": {
"age": 17,
"weight": 52.4,
"isMarried": true,
"info": "曾州市第一中学高三一班薛高",
"email": "zhangxue@163.com",
"score": [
96.1,
91.2
],
"name": {
"firstName": "高",
"lastName": "薛"
}
}
}
DELETE /alias_users/_doc/1
修改有两种方式:
- 全量修改:直接覆盖原来的文档。
- 增量修改:修改文档中的部分字段。
全量修改#
- 全量修改是覆盖原来的文档,其本质是:
- 根据指定的id删除文档。
- 新增一个相同id的文档。
- 注意:如果根据id删除时,id不存在,第二步的新增也会执行,也就从修改变成了新增操作了。
1
2
3
4
5
6
7
8
9
10
11
12
|
PUT /alias_users/_doc/1
{
"age": 20,
"weight": 50.0,
"info": "曾州市第一中学高三一班张薛",
"email": "zhangxue@163.com",
"score": [92.1, 93.2],
"name": {
"firstName": "薛",
"lastName": "张"
}
}
|
增量修改#
- 增量修改是只修改指定id匹配的文档中的部分字段。
1
2
3
4
5
6
|
POST /alias_users/_update/2
{
"doc": {
"age": 20
}
}
|
// 响应结果
{
"_index": "users",
"_id": "2",
"_version": 2,
"result": "updated",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 1
}