Skip to content

更新文档

全量更新

POST /user/docs/3
{
    "name": "王五",
    "sex": 1,
    "age": 25,
    "address": "河北省"
}
POST /user/docs/3
{
    "name": "王五",
    "sex": 1,
    "age": 25,
    "address": "河北省"
}

如果已经有ID为3这条数据,那么将全量更新

{
  "_index" : "user",
  "_type" : "docs",
  "_id" : "3",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 3,
  "_primary_term" : 1
}
{
  "_index" : "user",
  "_type" : "docs",
  "_id" : "3",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 3,
  "_primary_term" : 1
}

局部更新

POST /user/docs/3/_update
{
  "doc": {
    "name": "李达康"
  }
}
POST /user/docs/3/_update
{
  "doc": {
    "name": "李达康"
  }
}

更新成功返回

{
  "_index" : "user",
  "_type" : "docs",
  "_id" : "3",
  "_version" : 3,
  "result" : "noop",
  "_shards" : {
    "total" : 0,
    "successful" : 0,
    "failed" : 0
  },
  "_seq_no" : 4,
  "_primary_term" : 1
}
{
  "_index" : "user",
  "_type" : "docs",
  "_id" : "3",
  "_version" : 3,
  "result" : "noop",
  "_shards" : {
    "total" : 0,
    "successful" : 0,
    "failed" : 0
  },
  "_seq_no" : 4,
  "_primary_term" : 1
}

备案号:冀ICP备20015584号-2