es bulk update operation field values

Copyright: may not be reproduced without permission. https://blog.csdn.net/qq_35958788/article/details/89387389

Official Documents

curl -X POST "localhost:9200/twitter/_update_by_query" -H 'Content-Type: application/json' -d'
{
  "script": {
    "source": "ctx._source.likes++",
    "lang": "painless"
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}
'

Specific use

方式一:
{
  "script": {
    "source": "ctx._source.xxx='xxxxx'",
    "lang": "painless"
  },
  "query": {
    "term": {
      "xxxx": "xxxxx"
    }
  }
}
方式二:
{
  "script": {
    "source": "ctx._source['xxx']='xxxxx'",
    "lang": "painless"
  },
  "query": {
    "term": {
      "xxxx": "xxxxx"
    }
  }
}

Two or more given query are
given as follows:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "ctx._source[xxx]=xxxx",
          "            ^---- HERE"
        ],
        "script": "ctx._source[xxx]=xxxx",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "compile error",
    "script_stack": [
      "ctx._source[xxx]=xxxx",
      "            ^---- HERE"
    ],
    "script": "ctx._source[xxx]=xxxx",
    "lang": "painless",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Variable [xxx] is not defined."
    }
  },
  "status": 500
}
  • Reason: grammar es different versions can use a slightly different

amend as below:

curl -X POST "http://127.0.0.1:9200/indexxxx/_update_by_query" -H 'Content-Type: application/json' -d'
{
  "script": {
      "source": "ctx._source.name = params.xxxname",
      "params": { "xxxname": "abcabc" },
    "lang": "painless"
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
    }
  }
}
'

Guess you like

Origin blog.csdn.net/qq_35958788/article/details/89387389
Recommended