# How to copy from one nested field to another in elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-copy-from-one-nested-field-to-another-in-elasticsearch/283549>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [September 7, 2021, 2:42pm UTC](https://discuss.elastic.co/t/how-to-copy-from-one-nested-field-to-another-in-elasticsearch/283549 "2021-09-07T14:42:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)\
**Post date:** [September 7, 2021, 2:42pm UTC](https://discuss.elastic.co/t/how-to-copy-from-one-nested-field-to-another-in-elasticsearch/283549/1 "2021-09-07T14:42:23Z")

</div>

Hi all,

I'm trying to copy from one field to another.

I want to copy data from `fanLocation.lng` to `fanLocation.lon` in an index.  
I have already mapped both geo fields with `geo_point`  
i'm unable to use when using nested fields:

```auto
POST myindex/_update_by_query
{
   "script" : {
      "inline": "ctx._source.fanLocation.lon = ctx._source.fanLocation.lng", 
      "lang" : "painless"
   },
  "query": {
        "bool": {
            "must": [
                {
                    "match": {
                       "continent.keyword": "Europe"
                    }
                },
            ]
        }
    }
  }

```

I'm unable to do so.  
What is the correct format for nested fields?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 7, 2021, 3:56pm UTC](https://discuss.elastic.co/t/how-to-copy-from-one-nested-field-to-another-in-elasticsearch/283549/2 "2021-09-07T15:56:57Z")

</div>

Can you share a fully reproducible example including index and document creation? Thank you!

---

<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:** [October 5, 2021, 3:57pm UTC](https://discuss.elastic.co/t/how-to-copy-from-one-nested-field-to-another-in-elasticsearch/283549/3 "2021-10-05T15:57:33Z")

</div>

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