# Painless list collect

**URL:** <https://discuss.elastic.co/t/painless-list-collect/107378>\
**Category:** Elasticsearch\
**Created:** [November 13, 2017, 11:47am UTC](https://discuss.elastic.co/t/painless-list-collect/107378 "2017-11-13T11:47:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conall\_Prendergast](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Conall\_Prendergast](https://discuss.elastic.co/u/Conall_Prendergast)\
**Post date:** [November 13, 2017, 11:47am UTC](https://discuss.elastic.co/t/painless-list-collect/107378/1 "2017-11-13T11:47:44Z")

</div>

Hi,  
I am trying to do a script transform in painless, and am following an example I found [here](https://www.elastic.co/guide/en/watcher/current/actions.html) regarding list.collect syntax.

My painless script is:

```
      "transform" : {
        "script" : "return ctx.payload.hits.aggs.users_per_month.buckets.collect {it}",
    "lang": "painless"
  },

```

This is failing at the "}";

What is a painless script that will extract a certain field from each of the results, returning a list?

thanks

---

<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:** [November 15, 2017, 7:26am UTC](https://discuss.elastic.co/t/painless-list-collect/107378/2 "2017-11-15T07:26:57Z")

</div>

Those docs are from a previous version of watcher, when `groovy` scripting was recommended (which cannot just be changed by adding `"lang": "painless"`). Take a look at the [current docs](https://www.elastic.co/guide/en/x-pack/current/actions-slack.html).

---

<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:** [December 13, 2017, 7:26am UTC](https://discuss.elastic.co/t/painless-list-collect/107378/3 "2017-12-13T07:26:58Z")

</div>

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