# Ingest pipeline: copy all fields that contains a word to a single new field

**URL:** <https://discuss.elastic.co/t/ingest-pipeline-copy-all-fields-that-contains-a-word-to-a-single-new-field/338432>\
**Category:** Elasticsearch\
**Created:** [July 14, 2023, 6:38pm UTC](https://discuss.elastic.co/t/ingest-pipeline-copy-all-fields-that-contains-a-word-to-a-single-new-field/338432 "2023-07-14T18:38:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drjz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drjz/32/972_2.png) [@drjz](https://discuss.elastic.co/u/drjz)\
**Post date:** [July 14, 2023, 6:38pm UTC](https://discuss.elastic.co/t/ingest-pipeline-copy-all-fields-that-contains-a-word-to-a-single-new-field/338432/1 "2023-07-14T18:38:39Z")

</div>

Hi all, I am puzzling with the Script processor in an Ingest pipeline to copy all fields to a single new field. This is the same idea as using the copy\_to in the mapping, but instead of creating the copy in the index, we can store the copied values in the \_source using the Ingest pipeline. Can someone share a script that does exactly that?

So read all field-value pairs into a map and then copy them into a single new multi-valued field (array of strings).

---

<div class="post-metadata">

**Author:** ![PodarcisMuralis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podarcismuralis/32/122606_2.png) [@PodarcisMuralis](https://discuss.elastic.co/u/PodarcisMuralis)\
**Post date:** [July 14, 2023, 8:48pm UTC](https://discuss.elastic.co/t/ingest-pipeline-copy-all-fields-that-contains-a-word-to-a-single-new-field/338432/2 "2023-07-14T20:48:02Z")

</div>

Maybe this helps?

```auto
{
  "description": "Copy all fields to a single new field",
  "processors": [
    {
      "script": {
        "source": """
          def newField = [];
          for (entry in ctx.entrySet()) {
            newField.add(entry.getKey() + ": " + entry.getValue());
          }
          ctx['new_field'] = newField;
        """
      }
    }
  ]
}

```

---

<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:** [August 11, 2023, 8:48pm UTC](https://discuss.elastic.co/t/ingest-pipeline-copy-all-fields-that-contains-a-word-to-a-single-new-field/338432/3 "2023-08-11T20:48:09Z")

</div>

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