# Painless scripting params.entrySet()?

**URL:** <https://discuss.elastic.co/t/painless-scripting-params-entryset/143306>\
**Category:** Elasticsearch\
**Created:** [August 7, 2018, 11:04am UTC](https://discuss.elastic.co/t/painless-scripting-params-entryset/143306 "2018-08-07T11:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![panthersquirrel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panthersquirrel/32/31548_2.png) [@panthersquirrel](https://discuss.elastic.co/u/panthersquirrel)\
**Post date:** [August 7, 2018, 11:04am UTC](https://discuss.elastic.co/t/painless-scripting-params-entryset/143306/1 "2018-08-07T11:04:11Z")

</div>

If I have a document like this:

```auto
POST random/_doc/1
{
  "id": 1 
}

```

and i want to do:

```auto
POST random/_doc/1/_update
{
  "script": {
    "source": "
      for (entry in params.entrySet()) { 
        ctx._source[entry.getKey()] = entry.getValue();
      }
    ",
    "params": {
      "a": 1,
      "b": 2
    }, 
    "lang": "painless"
  }
}

```

it fails with

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[AZuCya_][172.17.0.3:9300][indices:data/write/update[s]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Iterable object is self-referencing itself"
  },
  "status": 400
}

```

I expected entrySet() to return keys: 'a', 'b', but it seems to be returning atleast the keys: 'ctx', 'a', 'b'. If i skip the 'ctx' field, all goes as intended.

```auto
POST random/_doc/1/_update
{
  "script": {
    "source": "
       for (entry in params.entrySet()) { 
         if (entry.getKey() != \"ctx\") { 
           ctx._source[entry.getKey()] = entry.getValue() 
         }
       }
    ",
    "params": {
      "a": 1,
      "b": 2
    }, 
    "lang": "painless"
  }
}

```

I'm wondering why this is? Is there another method to return only the keys/values given explicitly in the params object? I can go ahead and skip 'ctx' but i dont know if there are other keys i need to skip. Thoughts?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 7, 2018, 7:44pm UTC](https://discuss.elastic.co/t/painless-scripting-params-entryset/143306/2 "2018-08-07T19:44:12Z")

</div>

Unfortunately the way many scripts work right now is to add these variables into the `params` object which was parsed from the request. This is slowly being fixed as script usages are converted to script contexts. Update scripts should get this behavior by default in 7.0: [https://github.com/elastic/elasticsearch/pull/32096](https://github.com/elastic/elasticsearch/pull/32096).

---

<div class="post-metadata">

**Author:** ![panthersquirrel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panthersquirrel/32/31548_2.png) [@panthersquirrel](https://discuss.elastic.co/u/panthersquirrel)\
**Post date:** [August 7, 2018, 10:02pm UTC](https://discuss.elastic.co/t/painless-scripting-params-entryset/143306/3 "2018-08-07T22:02:46Z")

</div>

That’s great. Thanks! Can I assume for now that ctx is the only key I need to skip? It looks like it is, but this is already unexpected behavior, so I just want to be sure.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 4, 2018, 10:02pm UTC](https://discuss.elastic.co/t/painless-scripting-params-entryset/143306/4 "2018-09-04T22:02:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
