es head 新增字段、修改字段、批量修改字段、删除字段、删除数据、批量删除数据

目录

一、新增字段

二、修改字段值

三、批量修改字段值

​四、删除字段

五、删除数据/文档

六、批量删除数据/文档


一、新增字段

put   http://{ip}:{port}/{index}/_mapping/{type}    其中,index是es索引、type是类型

数据:

{
  "_doc": {
    "properties": {
      "report_time": {
        "type": "long"
      }
    }
  }
}

例子:

注意:如果报错Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true

需要在url后面加上  ?include_type_name=true

二、修改字段值

post   http://{ip}:{port}/{index}/_update/{id}    其中,index是es索引、id是文档_id

数据:

{
  "doc": {
    "report_time": 1701315235000
  }
}

样例:

三、批量修改字段值

post   http://{ip}:{port}/{index}/_update_by_query    其中,index是es索引

数据:把command_status字段等于1的数据的ip_address字段修改为2.2.2.2

{
  "query": {
    "match": {
      "command_status": 1
    }
  },
  "script": {
    "inline": "ctx._source['ip_address'] = '2.2.2.2'"
  }
}

如果需要修改索引里所有数据,去掉query即可

{
  "script": {
    "inline": "ctx._source['ip_address'] = '2.2.2.2'"
  }
}

四、删除字段

post   http://{ip}:{port}/{index}/_update_by_query    其中,index是es索引

数据: 删除ip_address字段

{
  "script": "ctx._source.remove('{ip_address}')",
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "ip_address"
          }
        }
      ]
    }
  }
}

五、删除数据/文档

delete   http://{ip}:{port}/{index}/{type}/{id}    其中,index是es索引、type是类型、id是文档_id

数据:无

六、批量删除数据/文档

post   http://{ip}:{port}/{index}/_delete_by_query   其中,index是es索引

数据:删除command_id等于1G7ZACL800908的数据或文档

{
  "query": {
    "match": {
      "command_id": "1G7ZACL800908"
    }
  }
}

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值