Teng's blog Teng's blog
首页
Java
H5前端
GitHub (opens new window)
首页
Java
H5前端
GitHub (opens new window)
  • 认知

  • 入门

    • 环境准备
    • RESTful&JSON
    • 客户端工具
    • 倒排索引
    • 数据格式
    • RESTful-API

      • 索引-创建
      • 索引-查询
      • 索引-删除
      • 文档-创建
      • 文档-主键查询
      • 文档-全量查询
      • 文档-删除
      • 文档-修改
        • 全量修改 POST _doc
        • 局部修改 POST _update
      • 映射-创建
      • 映射-查询
      • DSL-数据准备
      • DSL-全量查询
      • DSL-匹配查询
      • DSL-关键字查询
      • DSL-指定返回字段
      • DSL-组合查询
      • DSL-范围查询
      • DSL-模糊查询
      • DSL-排序
      • DSL-高亮
      • DSL-分页查询
      • DSL-聚合查询
    • Java-API

  • 环境

  • 进阶

  • 框架集成

  • 优化

  • 面试题

  • Database-Elasticsearch
  • 入门
  • RESTful-API
Shetengteng
2022-01-25

文档-修改

# 全量修改 POST _doc

和新增文档一样,输入相同的 URL 地址请求,如果请求体变化,会将原有的数据内容覆盖

在 Postman 中,向 ES 服务器发 POST 请求 : http://localhost:9200/shopping/_doc/1

POST http://localhost:9200/shopping/_doc/1
1

请求体

{
    "title":"华为手机",
    "category":"华为",
    "images":"http://my-notes.cn/hw.jpg",
    "price":1999.00
}
1
2
3
4
5
6

返回信息

{
    "_index": "shopping",
    "_type": "_doc",
    "_id": "1",
    "_version": 5,
    "result": "updated", // 表示数据被更新
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 7,
    "_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

使用PUT也是可以的

# 局部修改 POST _update

只修改某一给条数据的局部信息

在 Postman 中,向 ES 服务器发 POST 请求 : http://localhost:9200/shopping/_update/1

POST http://localhost:9200/shopping/_update/1
1

请求体

{
	"doc": {
		"title":"红米手机2",
		"category":"红米"
	}
}
1
2
3
4
5
6

返回信息

{
    "_index": "shopping",
    "_type": "_doc",
    "_id": "1",
    "_version": 7,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 9,
    "_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

注意:请求url中使用_update关键字

修改成功后,查询结果

GET http://localhost:9200/shopping/_doc/1

返回

{
    "_index": "shopping",
    "_type": "_doc",
    "_id": "1",
    "_version": 7,
    "_seq_no": 9,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "title": "红米手机2",
        "category": "红米",
        "images": "http://my-notes.cn/hw.jpg",
        "price": 1999.0
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Last Updated: 2022/02/05, 15:58:51
文档-删除
映射-创建

← 文档-删除 映射-创建→

Theme by Vdoing | Copyright © 2021-2022 Shetengteng | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式