zoukankan      html  css  js  c++  java
  • es head 新增字段并赋值

    //新增字段
    请求url:http://111.11.11.111:19200/es的index/_mapping/es的type/
    请求方法:put
    数据格式:
    {
      "es的type": {
        "properties": {
          "字段1": {
            "type": "string"
          },
          "字段2": {
            "type": "string"
          }
        }
      }
    }
    //赋值
    请求url:http://111.11.11.111:19200/es的type/_update_by_query/
    请求方法:post
    数据格式:
    {
      "script": {
        "lang": "painless",
        "inline": "ctx._source.字段= '值' "
      }
    }

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

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

    POST soc-system/_update_by_query
    {
      "script": {
        "source": "ctx._source['area']='无'" 
      },
      "query": {
        "bool": {
          "must_not": [
            {
              "exists": {
                "field": "area"
              }
            }
          ]
        }
      }
    }


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

    POST soc-system/_update_by_query
    {
      "script": {
        "source": "def a=ctx._source['ip'].lastIndexOf('.');def sec=ctx._source['ip'].substring(0,a);ctx._source['ipSection']=sec+'.0'"
      },
      "query": {
        "bool": {
          "must": [
            {
              "exists": {
                "field": "ip"
              }
            }
          ]
        }
      }
    }


    其中script的语法为painless
     

    正因为当初对未来做了太多的憧憬,所以对现在的自己尤其失望。生命中曾经有过的所有灿烂,终究都需要用寂寞来偿还。
  • 相关阅读:
    洛谷P3819 松江1843路
    洛谷P1896 [SCOI2005]互不侵犯King
    洛谷P1197 [JSOI2008]星球大战
    洛谷P1171 售货员的难题
    2017-10-24 NOIP模拟赛
    LibreOJ #6192. 「美团 CodeM 复赛」城市网络
    洛谷P2258 子矩阵
    Cogs 9. 中心台站建设
    Cogs 6. 线型网络
    洛谷P3138 [USACO16FEB]负载平衡Load Balancing_Silver
  • 原文地址:https://www.cnblogs.com/candlia/p/11919903.html
Copyright © 2011-2022 走看看