# Copying Value From Existing Field

**URL:** <https://discuss.elastic.co/t/copying-value-from-existing-field/133013>\
**Category:** Elasticsearch\
**Created:** [May 23, 2018, 3:01pm UTC](https://discuss.elastic.co/t/copying-value-from-existing-field/133013 "2018-05-23T15:01:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varan/32/32120_2.png) [@Varan](https://discuss.elastic.co/u/Varan)\
**Post date:** [May 23, 2018, 3:01pm UTC](https://discuss.elastic.co/t/copying-value-from-existing-field/133013/1 "2018-05-23T15:01:27Z")

</div>

Hi,

I have an index with data already indexed.  
I want to add a multi-field to an already existing field and to copy the content of the said field in it.

```
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "text",
}}}}}

```

`POST /entite/_doc/102/{ "doc": {"name" : "Ted"}}`

```
PUT my_index/_mapping/_doc
{
  "properties": {
    "name": {
      "type": "text",
      "fields": {
            "raw": { 
              "type": "keyword"}}}}}

```

But with this, name.raw is empty.  
I want to have "Ted" indexed in it without having to repost it.  
Is this possible?

NB: I've tried "copy\_to" but this doesn't seem to work with multi-field.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 23, 2018, 9:38pm UTC](https://discuss.elastic.co/t/copying-value-from-existing-field/133013/2 "2018-05-23T21:38:43Z")

</div>

It's not possible without reindexing. You can "upgrade" the field to have a multi-field (`raw` in this case), but all existing documents will have an empty `name.raw` as you discovered.

You'll have to index the docs again or use the reindex API.

This is done to make the cost explicit; imagine you have a petabyte of data and update the mapping to include a new mapping. If we auto-reindexed the field, there'd a petabyte of background reindexing that would get kicked off, and all sorts of dangerous edge-cases could pop up (what if the user changes it again during the process? What if the cluster crashes? etc etc).

---

<div class="post-metadata">

**Author:** ![Varan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varan/32/32120_2.png) [@Varan](https://discuss.elastic.co/u/Varan)\
**Post date:** [May 24, 2018, 8:00am UTC](https://discuss.elastic.co/t/copying-value-from-existing-field/133013/3 "2018-05-24T08:00:46Z")

</div>

Thank you.  
And could you confirm me that this multi-field does not take any place in the source?  
"Ted" would not be indexed twice as a name and a name.raw ?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 24, 2018, 2:29pm UTC](https://discuss.elastic.co/t/copying-value-from-existing-field/133013/4 "2018-05-24T14:29:09Z")

</div>

> [@Varan](#):
>
> And could you confirm me that this multi-field does not take any place in the source?

Correct. Elasticsearch never alters the original JSON source, so what you send is what you get back in `_source`.

> [@Varan](#):
>
> "Ted" would not be indexed twice as a name and a name.raw ?

Mostly a confusion of terms, but _technically_ "Ted" _will_ be indexed twice. When you add a multifield, what you're doing is telling Elasticsearch to index the field different ways, using different analyzers. So the value will be added into an inverted index for each extra multi-field that you add.

It'll still only show up once in the `_source`, but internally it will be indexed multiple times to support the multi-field.

---

<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:** [June 21, 2018, 2:29pm UTC](https://discuss.elastic.co/t/copying-value-from-existing-field/133013/5 "2018-06-21T14:29:13Z")

</div>

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