如何在同时具有两个“脚本"的ES上发出单个更新请求?和"doc" ..? [英] How do i make a single update request on ES having both "script" and "doc"..?

查看:54
本文介绍了如何在同时具有两个“脚本"的ES上发出单个更新请求?和"doc" ..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文档"请求:

POST test_v2/_update/Z_nM_2wBjkGOA-r6ArOb
{
  "doc": {
    "CD": {
      "middle": "prakash",
      "first": "raj"
    }
  },
  "doc_as_upsert": "true"
}

我的脚本"请求:

POST test_v2/_update/Z_nM_2wBjkGOA-r6ArOb
{
  "script": {
    "lang": "painless",
    "inline": "if(!ctx._source.containsKey('nested_field')){ctx._source['nested_field']=[]}ctx._source.nested_field.add(params.object)",
    "params": {
      "object": {
        "model": "tata nano",
        "value": "2"
      }
    }
  }
}

我想同时加入脚本"和文档",并向他们提出一个请求,请帮助我实现这一目标.我正在使用ES v7.3.根据ES的说法,我不能将两个请求都包含在一个请求中.

I wanted to join both this 'script' and 'doc' and make a single request for them please help me achieve this. i am using ES v7.3. According to ES I cannot have both of them inside a single request.

推荐答案

ctx._source ['CD'] = params.object1 --->将更新或添加新字段

ctx._source['CD']=params.object1 ---> will update or add new field

POST test3/_update/30RaAG0BY3127H1HaOEv
{
  "scripted_upsert":true,
  "script": {
    "lang": "painless",
    "inline": "ctx._source['CD']=params.object1; if(!ctx._source.containsKey('comments')){ctx._source['comments']=[]}ctx._source.comments.add(params.object)",
    "params": {
      "object": {
        "model": "tata nano",
        "value": "2"
      },
      "object1": {
      "middle": "prakash1",
      "first": "raj1"
    }
    }
  },
  "upsert" : {}
}

这篇关于如何在同时具有两个“脚本"的ES上发出单个更新请求?和"doc" ..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆