# How to pass a parameter to a script attached to a runtime field

**URL:** <https://discuss.elastic.co/t/how-to-pass-a-parameter-to-a-script-attached-to-a-runtime-field/303348>\
**Category:** Elasticsearch\
**Tags:** runtime-fields\
**Created:** [April 27, 2022, 7:29am UTC](https://discuss.elastic.co/t/how-to-pass-a-parameter-to-a-script-attached-to-a-runtime-field/303348 "2022-04-27T07:29:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankmontyne](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@frankmontyne](https://discuss.elastic.co/u/frankmontyne)\
**Post date:** [April 27, 2022, 7:29am UTC](https://discuss.elastic.co/t/how-to-pass-a-parameter-to-a-script-attached-to-a-runtime-field/303348/1 "2022-04-27T07:29:01Z")

</div>

Hi,

Can anyone help me how to pass a parameter to a script attached to a runtime field? With scripted fields 'params' can be used to get to the parameters passed to the script but for runtime fields this does not seem to work. If possible an example in java code would be great!

Thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 27, 2022, 8:16am UTC](https://discuss.elastic.co/t/how-to-pass-a-parameter-to-a-script-attached-to-a-runtime-field/303348/2 "2022-04-27T08:16:03Z")

</div>

Can you share, what you tried and what version you are on, this snippet seems to work for me on 8.1:

```auto
GET my-index-000001/_search
{
  "runtime_mappings": {
    "day_of_week": {
      "type": "keyword",
      "script": {
        "source": "emit(doc[params.field].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))",
        "params": {
          "field":"@timestamp"
        }
      }
    }
  },
  "aggs": {
    "day_of_week": {
      "terms": {
        "field": "day_of_week"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![frankmontyne](https://avatars.discourse-cdn.com/v4/letter/f/c6cbf5/32.png) [@frankmontyne](https://discuss.elastic.co/u/frankmontyne)\
**Post date:** [May 16, 2022, 10:25am UTC](https://discuss.elastic.co/t/how-to-pass-a-parameter-to-a-script-attached-to-a-runtime-field/303348/3 "2022-05-16T10:25:04Z")

</div>

Yes indeed I meanwhile figured that out also. Thanks anyway!

---

<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:** [June 13, 2022, 10:25am UTC](https://discuss.elastic.co/t/how-to-pass-a-parameter-to-a-script-attached-to-a-runtime-field/303348/4 "2022-06-13T10:25:31Z")

</div>

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