ES 修改数据

方法一:PUT

和CREATE一样,PUT的时候将所有field带上,只调整修改的部分即可

PUT /spouse/female/5
{
  "name":"lengmeng",
  "age":26,
  "desc":"actress"
}

返回结果;

{
  "_index" : "spouse",
  "_type" : "female",
  "_id" : "5",
  "_version" : 2,   // 修改后,_version会+1,值代表数据改动的次数
  "result" : "updated", 
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 6,
  "_primary_term" : 1
}

方法二: POST: 和PUT相同的方式

POST /spouse/female/5
{
  "name":"lengmeng",
  "age":18,
  "desc":"actress"
}

注意,这种方法修改时,需要带上所有field,否则该field会消失;如下

POST /spouse/female/5
{
  "name":"lengmeng",
  "age":19
}
--返回
{
  "_index" : "spouse",
  "_type" : "female",
  "_id" : "5",
  "_version" : 5,
  "_seq_no" : 9,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "lengmeng",
    "age" : 19
  }
}

方法三:(推荐)

例如我想只修改age为 18 ,其他信息不改,就采用_update方法

POST /spouse/female/5/_update
{
  "doc":{
    "age":22
  }
}

--返回
{
  "_index" : "spouse",
  "_type" : "female",
  "_id" : "5",
  "_version" : 7,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 11,
  "_primary_term" : 1
}

查询结果可以看到,id=5的文档下,name和desc都存在

{
  "_index" : "spouse",
  "_type" : "female",
  "_id" : "5",
  "_version" : 7,
  "_seq_no" : 11,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "lengmeng",
    "age" : 22,
    "desc" : "actress"
  }
}

你可能感兴趣的:(ELK,elasticsearch,大数据,big,data)