elasticSearch用head 新增字段,或数据

 
 

 

转自: https://blog.csdn.net/ZYC88888/article/details/94756744

 

 

 

 

 

 
//新增字段
  1.  
    请求url:http://111.11.11.111:19200/es的index/_mapping/es的type/
  2.  
    请求方法:put
  3.  
    数据格式:
  4.  
    {
  5.  
    "es的type": {
  6.  
    "properties": {
  7.  
    "字段1": {
  8.  
    "type": "string"
  9.  
    },
  10.  
    "字段2": {
  11.  
    "type": "string"
  12.  
    }
  13.  
    }
  14.  
    }
  15.  
    }
 
 
  1.  
    //赋值
  2.  
    请求url:http://111.11.11.111:19200/es的type/_update_by_query/
  3.  
    请求方法:post
  4.  
    数据格式:
  5.  
    {
  6.  
    "script": {
  7.  
    "lang": "painless",
  8.  
    "inline": "ctx._source.字段= '值' "
  9.  
    }
  10.  
    }
 

ElasticSearch的update_by_query语句可以很方便地为原有es表修改字段和新增字段,如下面的例子所示:

1.将资产表中area为空的字段赋值为'无'

 
  1.  
    POST soc-system/_update_by_query
  2.  
    {
  3.  
      "script": {
  4.  
        "source": "ctx._source['area']='无'" 
  5.  
      },
  6.  
      "query": {
  7.  
        "bool": {
  8.  
          "must_not": [
  9.  
            {
  10.  
              "exists": {
  11.  
                "field": "area"
  12.  
              }
  13.  
            }
  14.  
          ]
  15.  
        }
  16.  
      }
  17.  
    }
 


2.添加一个网段字段,其值根据已有字段ip截取而来

 
  1.  
    POST soc-system/_update_by_query
  2.  
    {
  3.  
      "script": {
  4.  
        "source": "def a=ctx._source['ip'].lastIndexOf('.');def sec=ctx._source['ip'].substring(0,a);ctx._source['ipSection']=sec+'.0'"
  5.  
      },
  6.  
      "query": {
  7.  
        "bool": {
  8.  
          "must": [
  9.  
            {
  10.  
              "exists": {
  11.  
                "field": "ip"
  12.  
              }
  13.  
            }
  14.  
          ]
  15.  
        }
  16.  
      }
  17.  
    }
 


其中script的语法为painless
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值