kibana Dev Tools--修改语句示例

kibana Dev Tools中修改、新增数据示例

kibana Dev Tools增删改查基础知识:https://www.cnblogs.com/bigfacecat-h/p/14490917.html
kibana Dev Tools查询示例:https://www.cnblogs.com/bigfacecat-h/p/elasticSearch.html
kibana Dev Tools修改示例:https://www.cnblogs.com/bigfacecat-h/p/14498221.html
kibana Dev Tools常用命令:https://www.cnblogs.com/bigfacecat-h/p/14500466.html

目录:

1、POST请求的特点

2、PUT请求的特点

3、使用_update_by_query 修改某个字段

4、使用_update修改某个字段

kibana Dev Tools中新增、修改数据可以使用POST、PUT请求,但两者有区别

1、创建/修改索引时,POST命令不需要指定文档id(可以指定也可以不指定)

     POST不指定文档id时:是在同样的索引下新增了一条数据(幂等操作)

     POST指定了文档id时:若该文档id不存在,则创建索引;若文档id已存在,则执行更新操作(若新提交的字段不存在则增加该字段,若该字段已存在则更新该字段的值,其他字段值则删掉)

 

2、创建/修改索引时,PUT必须指定文档id

      若文档id不存在,则创建索引

      若文档id已存在,则执行更新操作(将请求中的整个json值完全替换掉旧的值)

 

 

 

3、通过查询条件来限定修改范围的方式修改某字段的值

update  xxx.yyy.topic  set  result='[{"aWord":"1哈哈哈哈","count":1,"locations":["00:05-00:08","01:01-01:02"]}]'    where   update_time >= 1591200000000  and update_time <= 1591362000000

POST  xxx.yyy.topic/logs/_update_by_query
{
   "query": {
    "bool": {
      "must": [
         {
          "range": {
              "update_time": {
                 "gte": 1591200000000,
                 "lte": 1591362000000
                       }
                   }
         }
        ]
      }
    },
    "script": {
         "source": "ctx._source['result']='[{"aWord":"1哈哈哈哈","count":1,"locations":["00:05-00:08","01:01-01:02"]}]'"
    }
}

json串中带有特殊字符",需要用进行转义

gte  --表示大于等于

lte --表示小于等于

POST /index_bigfacecat_test/typeA/_update_by_query
{
  "query":{
    "bool":{
      "must":[
        {
          "match":{
            "name":"大脸猫2"
          }
        }
      ]
    }
  },
  "script":{
    "source":"ctx._source['name']='Big Face Cat2'"
  }
  
}
POST /index_bigfacecat_test/typeA/_update
{
  "script":"ctx._source.workdays+= 5"
}

  

4、用主键作为条件来修改某个字段的值

update  xxx.yyy.topic    set   result = '[{"aWord":"1哈哈哈哈","count":1,"locations":["00:05-00:08","01:01-01:02"]}'    where  _id = 'xx-b2fc-43ca-afe7-77e3ff406ff9'

POST xxx.yyy.topic/logs/xx-b2fc-43ca-afe7-77e3ff406ff9/_update
{
   "doc":{
    "result": """[{"aWord":"1哈哈哈哈","count":1,"locations":["00:05-00:08","01:01-01:02"]}]"""
  }
}
POST xxx.yyy.topic/logs/xx-b2fc-43ca-afe7-77e3ff406ff9/_update

{  "doc":{
    "result": "哈哈哈" 
} }

注意:json中带有特殊字符,需要两个"""包起来

原文地址:https://www.cnblogs.com/bigfacecat-h/p/14498221.html