关于elasticsearch用_update局部更新失败的问题

关于elasticsearch用_update局部更新失败的问题


错误信息

“error” : “no handler found for uri [/test/_doc/001/_update?pretty=true] and method [POST]”


ElasticSearch部分更新

根据文档学习ElasticSearch的Rest风格对索引增删改,在更新部分,如果不设置某些值,会将不修改的值清空。因为文档是不可变的,不能更改,只能被替换。所以修改文档只是用新的文档,覆盖现有文档中,所以就是修改会把没有提及的值清空的原因。

Elastic Search提供了局部更新_update 关键字。

测试

  • 新增测试数据
POST test/_doc/001
{
  "nick": "及时雨", 
  "name": "宋江"
}
GET /test/_search

结果

{
  "took" : 647,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_id" : "001",
        "_score" : 1.0,
        "_source" : {
          "nick" : "及时雨",
          "name" : "曹操"
        }
      }
    ]
  }
}
  • 修改name
POST /test/_doc/001/_update
{
  "doc": {
    "name": "宋江"
  }
}

结果

{
  "error" : "no handler found for uri [/test/_doc/001/_update?pretty=true] and method [POST]"
}

elasticsearch8.0之后对一些API进行修改,正确的URI如下

POST /test/_update/001
{
  "doc": {
    "name": "宋江"
  }
}

结果

{
  "_index" : "test",
  "_id" : "001",
  "_version" : 5,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 4,
  "_primary_term" : 1
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值