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

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).

Maybe this helps?

  "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;
1 Like

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