# Upgrading to 2.x: convert "index\_name" to "copy\_to"

**URL:** <https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487>\
**Category:** Elasticsearch\
**Created:** [April 6, 2016, 7:39am UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487 "2016-04-06T07:39:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![newgene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/newgene/32/8926_2.png) [@newgene](https://discuss.elastic.co/u/newgene)\
**Post date:** [April 6, 2016, 7:39am UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/1 "2016-04-06T07:39:46Z")

</div>

Hi, we are upgrading our elasticsearch from 1.7.5 to 2.3. There is one case in our mapping seems having problem to reproduce the same query behavior in 1.7:

mapping

```
{
    "dynamic": False,
    "properties": {
		"aaa": {
			"properties": {
				"b1": {
					"type": "string",
                                        "copy_to": "aaa"
				},
				"b2": {
					"type": "string",
                                        "copy_to": "aaa"
				}
			}
		}
	}
}

```

Previously, we allow users to query fields on "aaa.b1", "aaa.b2", and just "aaa" field for either b1 or b2 by combining "path": "just\_name" and "index\_name": "aaa" in the mapping. However, now with copy\_to, we cannot index values from aaa.b1, and aaa.b2 collectively to just "aaa" as "aaa" is now defined as an object field.

Any solution for that?

Thanks!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2016, 7:54am UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/2 "2016-04-06T07:54:03Z")

</div>

w00t! That sounds like a hack to me!

Funny...

You can may be try to copy to `aaa.aaa` which might work but I'm super unsure...

---

<div class="post-metadata">

**Author:** ![newgene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/newgene/32/8926_2.png) [@newgene](https://discuss.elastic.co/u/newgene)\
**Post date:** [April 6, 2016, 3:30pm UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/3 "2016-04-06T15:30:15Z")

</div>

For example a use case might be:

{“response”: {“src1”: “value1”},{“src2”:“value2”}}

I would like our users can query on “response” field for either value1 or value2. I know I can do response.all as the copy\_to field, but query on “response” field is more natural to our users, as it follows an ontology we are using, and users have an expectation to query on response field. I also cannot construct the data as

{“response”: [“value1”, “value2”]}

As it loses the src info.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2016, 6:21pm UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/4 "2016-04-06T18:21:16Z")

</div>

Did you try what I wrote?

---

<div class="post-metadata">

**Author:** ![newgene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/newgene/32/8926_2.png) [@newgene](https://discuss.elastic.co/u/newgene)\
**Post date:** [April 6, 2016, 11:14pm UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/5 "2016-04-06T23:14:12Z")

</div>

Hi David, just tried. It only makes query "aaa.aaa:v1" work, but not "aaa:v1".

The mapping looks like this:

```
m1 = {
    "dynamic": False,
    "properties": {
		"aaa": {
			"properties": {
				"b1": {
					"type": "string",
                                        "copy_to": "aaa.aaa"
				},
				"b2": {
					"type": "string",
                                        "copy_to": "aaa.aaa"
				},
                "aaa" : {"type": "string"}
			}
		}
	}
}

```

and the test doc is:

```
{"aaa":{"b1": "v1", "b2":"v2"}}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 7, 2016, 7:03am UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/6 "2016-04-07T07:03:59Z")

</div>

Note: please use `</>` when posting code. I updated your answer.

Well. Yes... So I don't see any other solution than reworking your json content.  
Not sure if in your ingestion pipeline you can mutate some fields and for example instead of indexing:

```auto
{
  "foo": {
     "a": "bar",
     "b": "baz"
}

```

index

```auto
{
  "fake_foo": {
     "a": "bar",
     "b": "baz"
}

```

And then use `copy_to` to copy `fake_foo.a` and `fake_foo.b` to `foo`?  
Potentially use the same `copy_to` feature to copy `fake_foo.a` to `foo.a` and `fake_foo.b` to `foo.b`?  
Then don't index `fake_*`.

Can't see another way to achieve the same.

I hope this could help.

---

<div class="post-metadata">

**Author:** ![newgene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/newgene/32/8926_2.png) [@newgene](https://discuss.elastic.co/u/newgene)\
**Post date:** [April 10, 2016, 3:43pm UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/7 "2016-04-10T15:43:57Z")

</div>

Thanks! For now I think I can ask users to query as `"aaa.*:value1"`, instead of previous `"aaa:value1"`. Changing the json structure is not ideal, as this structure is relatively fixed.

---

<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:** [July 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/upgrading-to-2-x-convert-index-name-to-copy-to/46487/8 "2017-07-05T23:00:54Z")

</div>


