# Ingest pipeline to copy data from one field to another based on condition

**URL:** <https://discuss.elastic.co/t/ingest-pipeline-to-copy-data-from-one-field-to-another-based-on-condition/293352>\
**Category:** Kibana\
**Created:** [January 3, 2022, 1:50pm UTC](https://discuss.elastic.co/t/ingest-pipeline-to-copy-data-from-one-field-to-another-based-on-condition/293352 "2022-01-03T13:50:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sugand](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Sugand](https://discuss.elastic.co/u/Sugand)\
**Post date:** [January 3, 2022, 1:50pm UTC](https://discuss.elastic.co/t/ingest-pipeline-to-copy-data-from-one-field-to-another-based-on-condition/293352/1 "2022-01-03T13:50:05Z")

</div>

Hi,

I'm looking to copy data from one field to another, if initially the destination field is blank assign a value, if non blank don't overwrite to another but upon re-indexing from another source the doc pipeline doesn't seem to work as the destination fields are blank post the run of pipeline but when manually updated the code does work.

```auto
PUT _ingest/pipeline/auto_now_add_new
{
  "processors": [
    {
      "script": {
        "source": """
          if (ctx['bkp_email'] != null) { return; }
          
          ctx['bkp_email'] = ctx['email'];
        """
      }
     },
      {
      "script": {
        "source": """
          // don't overwrite if present
          if (ctx['bkp_phone'] != null) { return; }
          
          ctx['bkp_phone'] = ctx['phone'];
        """
      }
   }
  ]
}

```

Not sure if I'm missing something,

Appreciate your input's

Thanks,

---

<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:** [January 31, 2022, 1:50pm UTC](https://discuss.elastic.co/t/ingest-pipeline-to-copy-data-from-one-field-to-another-based-on-condition/293352/2 "2022-01-31T13:50:44Z")

</div>

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