# Can I copy values from different field to a single field in Elastic

**URL:** <https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335>\
**Category:** Elasticsearch\
**Tags:** ingest-pipeline\
**Created:** [December 2, 2024, 7:20pm UTC](https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335 "2024-12-02T19:20:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [December 2, 2024, 7:20pm UTC](https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335/1 "2024-12-02T19:20:01Z")

</div>

Hi,

I want to copy values from multiple fields into single field using split pipeline.

Below is the pipeline I have created, I am copying field values from title and abstract to suggest field.

```auto
[
  {
    "split": {
      "field": "title",
      "separator": "\\s+",
      "target_field": "suggest",
      "ignore_missing": true
    }
  },
  {
    "split": {
      "field": "abstract",
      "separator": "\\s+",
      "target_field": "suggest",
      "ignore_missing": true
    }
  }
]

```

The issue I am facing here is the field values are getting ovverriden. for Example.

```auto
POST /_ingest/pipeline/split_pipeline/_simulate
{
  "docs": [
    {
      "_source": {
        "title": "value1 value2",
        "abstract": "value3 value4"
      }
    }
  ]
}

```

Above query is returning below output

```auto
{
  "docs": [
    {
      "doc": {
        "_index": "_index",
        "_version": "-3",
        "_id": "_id",
        "_source": {
          "abstract": "value3 value4",
          "suggest": [
            "value3",
            "value4"
          ],
          "title": "value1 value2"
        },
        "_ingest": {
          "timestamp": "2024-12-02T19:07:43.091134491Z"
        }
      }
    }
  ]
}

```

However I want the below output.

```auto
{
  "docs": [
    {
      "doc": {
        "_index": "_index",
        "_version": "-3",
        "_id": "_id",
        "_source": {
          "abstract": "value3 value4",
          "suggest": [
           "value1", 
            "value2",
            "value3",
            "value4"
          ],
          "title": "value1 value2"
        },
        "_ingest": {
          "timestamp": "2024-12-02T19:07:43.091134491Z"
        }
      }
    }
  ]
}

```

Can somebody help me how can I achieve it through split\_pipeline (I don't want to use copy\_To functionality)??

---

<div class="post-metadata">

**Author:** ![strawgate](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/strawgate/32/131008_2.png) [@strawgate](https://discuss.elastic.co/u/strawgate)\
**Post date:** [December 2, 2024, 7:47pm UTC](https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335/2 "2024-12-02T19:47:34Z")

</div>

I believe you could use split to produce two different fields, then use the append processor to combine them: [Append processor | Elasticsearch Guide [8.16] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/append-processor.html)

And then drop the extra field

---

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [December 2, 2024, 8:14pm UTC](https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335/3 "2024-12-02T20:14:53Z")

</div>

Thanks You !!,

Please let me know if I am doing something wrong here.  
Below is what you are trying to say right ?

```auto
PUT _ingest/pipeline/split_pipeline
{
  "description": "Split values from multiple fields into one target field based on space",
  "processors": [
  {
    "split": {
      "field": "title",
      "separator": "\\s+",
      "target_field": "titlecopy"
    }
  },
  {
    "split": {
      "field": "abstract",
      "separator": "\\s+",
      "target_field": "abstractcopy"
    }
  },
  {
    "append": {
      "field": "suggest",
      "value": [
        "{{{titlecopy}}}",
        "{{{abstractcopy}}}"
      ],
      "allow_duplicates": false
    }
  },
  {
    "remove": {
      "field": [
        "titlecopy",
        "abstractcopy"
      ],
      "ignore_missing": true
    }
  }
]
}

```

Testing pipeline

```auto
POST /_ingest/pipeline/split_pipeline/_simulate
{
  "docs": [
    {
      "_source": {
        "title": "value1 value2",
        "abstract": "value3 value4"
      }
    }
  ]
}

```

Getting below as output.

```auto
{
  "docs": [
    {
      "doc": {
        "_index": "_index",
        "_version": "-3",
        "_id": "_id",
        "_source": {
          "abstract": "value3 value4",
          "suggest": [
            "{0=value1, 1=value2}",
            "{0=value3, 1=value4}"
          ],
          "title": "value1 value2"
        },
        "_ingest": {
          "timestamp": "2024-12-02T20:11:36.015890973Z"
        }
      }
    }
  ]
}

```

However my desired output should be

```auto
 "suggest": [
            "value1", "value2",
            "value3", "value4"
          ],

```

---

<div class="post-metadata">

**Author:** ![strawgate](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/strawgate/32/131008_2.png) [@strawgate](https://discuss.elastic.co/u/strawgate)\
**Post date:** [December 2, 2024, 8:24pm UTC](https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335/4 "2024-12-02T20:24:07Z")

</div>

Hmmm yeah, I misread the description though looking at this again you may be able to combine the foreach processor with the append processor to loop through the elements in field2 and append them to field1 (or a third field)

> **[Foreach processor | Elasticsearch Guide \[8.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/foreach-processor.html)**

---

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [December 2, 2024, 8:41pm UTC](https://discuss.elastic.co/t/can-i-copy-values-from-different-field-to-a-single-field-in-elastic/371335/5 "2024-12-02T20:41:01Z")

</div>

It worked!!!

Thank you very much
