一尘不染

Spring搜索部分更新

elasticsearch

我想做如下的部分更新。添加一些新字段,例如Bytes_In和Bytes_Out。并且还运行脚本来更新使用脚本从其他字段派生的字段。

脚本session-duration-script.groovy在/ config / scripts路径下。

ctx._source.duration= (new Date().parse("yyyy-MM-dd HH:mm:ss.SSS",ctx._source.sessionTerminationDateTime.replace("T", " ").substring(0,23)).getTime() - new Date().parse("yyyy-MM-dd HH:mm:ss.SSS",ctx._source.eventConversionDateTime.replace("T", " ").substring(0,23)).getTime())


access/access-event-logs/session-summary/0a30fd59karabip1new.lab.fp.f5net.com/_update   
{
       "doc" : {
          "active" : false,
          "Bytes_In": "100",
          "Bytes_Out": "100",
          "sessionTerminationDateTime": "2015-10-30T02:50:39.237Z"
       },
       "script_fields": {
               "my_field": {
                   "script_file": "session-duration-script"
                 }
        }
    }

当我运行上述更新查询时,出现此错误

{
  "code": 400,
  "message": "status:400, body:{\"error\":{\"root_cause\":[{\"type\":\"action_request_validation_exception\",\"reason\":\"Validation Failed: 1: can't provide both script and doc;\"}],\"type\":\"action_request_validation_exception\",\"reason\":\"Validation Failed: 1: can't provide both script and doc;\"},\"status\":400}",
  "originalRequestBody": "{\"error\":{\"root_cause\":[{\"type\":\"action_request_validation_exception\",\"reason\":\"Validation Failed: 1: can't provide both script and doc;\"}],\"type\":\"action_request_validation_exception\",\"reason\":\"Validation Failed: 1: can't provide both script and doc;\"},\"status\":400}",
  "referer": "172.17.86.67",
  "restOperationId": 6555035,
  "kind": ":resterrorresponse"
}

请让我知道有办法实现这种更新。


阅读 275

收藏
2020-06-22

共1个答案

一尘不染

由于错误状态,您不能同时使用docscript。我的建议是修改脚本,以添加所需的字段,并使用params地图传递这些字段的值。

2020-06-22