# Script processor ingest pipelines on nested fields

**URL:** <https://discuss.elastic.co/t/script-processor-ingest-pipelines-on-nested-fields/172092>\
**Category:** Elasticsearch\
**Created:** [March 13, 2019, 9:01am UTC](https://discuss.elastic.co/t/script-processor-ingest-pipelines-on-nested-fields/172092 "2019-03-13T09:01:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gbrown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gbrown/32/34482_2.png) [@gbrown](https://discuss.elastic.co/u/gbrown)\
**Post date:** [March 13, 2019, 10:42pm UTC](https://discuss.elastic.co/t/script-processor-ingest-pipelines-on-nested-fields/172092/2 "2019-03-13T22:42:52Z")

</div>

The lists of objects will simply be Painless lists in the script, so you can iterate over them just like any other list. This case is especially straightforward using Streams, e.g.:

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "source": """
          ctx.interesting_avg = ctx.things.stream()
            .mapToInt(thing -> thing.interesting)
            .average()
            .orElse(0)
          """
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "things": [
          {
            "interesting": 35
          },
          {
            "interesting": 42
          },
          {
            "interesting": 12
          }
        ]
      }
    }
  ]
}

```

Which returns:

```auto
{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_type",
        "_id" : "_id",
        "_source" : {
          "things" : [
            {
              "interesting" : 35
            },
            {
              "interesting" : 42
            },
            {
              "interesting" : 12
            }
          ],
          "interesting_avg" : 29.666666666666668
        },
        "_ingest" : {
          "timestamp" : "2019-03-13T22:40:27.030Z"
        }
      }
    }
  ]
}

```

Does that help you?

---

_[View the full topic](https://discuss.elastic.co/t/script-processor-ingest-pipelines-on-nested-fields/172092)._
