es调用脚本

1、内部脚本("script" : "ctx._source" 是内部定义好的获取_source数据的方式,不用改变)
POST /index/type/id/_update
{
  "script" : "ctx._source.field=any_result"
}

2、外部脚本
定义一个外部脚本,名称为aa.groovy,脚本内容为ctx._source.num+=new_num
POST /test_index/test_type/id/_update
{
  "script" : {
    "lang" : "groovy",
    "file" : "aa",
    "params" : {
      "new_num" : 1
    }
  }
}

3、用脚本删除文档
定义一个外部脚本,名称为test_delete.groovy,脚本内容为 ctx.op = ctx._source.num == count ? 'delete' : 'none'
POST /test_index/test_type/id/_update
{
  "script" : {
    "lang" : "groovy",
    "file" : "test_delete",
    "params" : {
      "count" : 1
    }
  }
}

原文地址:https://www.cnblogs.com/qinjf/p/8506341.html