I am trying to write a stored script that will iterate through the params and update the ctx._source fields from those parameters. I can't seem to figure out the correct way to do this without hardcoding the field names (e.g. ctx._source.field).

    POST _scripts/update-on-version
    {
      "script": {
        "lang": "painless",
        "code": "if (ctx._source.myVersion == null || ctx._source.myVersion <= params.myVersion) { for (entry in params.entrySet()) { ctx._source.put(entry.getKey(),entry.getValue()) } } else { ctx.op = 'none' }"
      }
    }

    POST service/service/2b38607f-e626-4a9e-a0ac-322bde377548/_update
    {
      "scripted_upsert": true,
        "script" : {
            "stored": "update-on-version",
            "params": {
              "myVersion": 1294698,
              "firstName": "Testname1",
              "lastName": "Testname1"
            }
        }
    }

    {
      "error": {
        "root_cause": [
          {
            "type": "remote_transport_exception",
            "reason": "[node-01][10.10.68.101:9343][indices:data/write/update[s]]"
          }
        ],
        "type": "illegal_argument_exception",
        "reason": "Object has already been built and is self-referencing itself"
      },
      "status": 400
    }

---
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB