# Migration of 2.3 indices to 5.6 using Painless

**URL:** <https://discuss.elastic.co/t/migration-of-2-3-indices-to-5-6-using-painless/108859>\
**Category:** Elasticsearch\
**Created:** [November 23, 2017, 9:49am UTC](https://discuss.elastic.co/t/migration-of-2-3-indices-to-5-6-using-painless/108859 "2017-11-23T09:49:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bostjan\_Kovac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bostjan_kovac/32/9671_2.png) [@Bostjan\_Kovac](https://discuss.elastic.co/u/Bostjan_Kovac)\
**Post date:** [November 23, 2017, 9:49am UTC](https://discuss.elastic.co/t/migration-of-2-3-indices-to-5-6-using-painless/108859/1 "2017-11-23T09:49:40Z")

</div>

hi,

I have trouble with Painless scripting language and I cannot find any helpful info about my problem. My case is I want to migrate 2.3 ES index to 5.6 and create inner objects from some flat fields on 2.3. Source field is enabled. So basically:

v2.3:  
{  
"flat1" : "val1",  
"@flat2": "val2"  
}

in v5.6 I want:  
{  
"flat1": "val1",  
"newInnerObj": {  
"@flat2" : "val2"  
}  
}

also note the '@' sign in front of the field, might cause problems.

I tried this script and lost of other variations of it:  
POST \_reindex  
{  
"source": {  
"index": "src\_idx"  
},  
"dest": {  
"index": "dst\_idx"  
},  
"script": {  
"source": "if (ctx.\_source['@flat2'] != null) { ctx.\_source.add('newInnerObj'); ctx.\_source.newInnerObj.@flat2 = ctx.\_source.@flat2; ctx.\_source.remove('@flat2') }",  
"lang": "painless"  
}  
}

so the following is bothering me:

- how do I create inner objects in the script (I need to create newInnerObj, because it didn't exist in the old index?)
- how do I reference properties prefixed with '@'? should ctx.\_source['@flat2'] work?

---

<div class="post-metadata">

**Author:** ![Bostjan\_Kovac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bostjan_kovac/32/9671_2.png) [@Bostjan\_Kovac](https://discuss.elastic.co/u/Bostjan_Kovac)\
**Post date:** [November 23, 2017, 2:30pm UTC](https://discuss.elastic.co/t/migration-of-2-3-indices-to-5-6-using-painless/108859/2 "2017-11-23T14:30:57Z")

</div>

correct instantiation of the inner object is done via:

```
Map inner = new HashMap(); ctx._source.innder = inner;
```

---

<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:** [December 21, 2017, 2:31pm UTC](https://discuss.elastic.co/t/migration-of-2-3-indices-to-5-6-using-painless/108859/3 "2017-12-21T14:31:02Z")

</div>

Closed on December 21, 2017, 2:31pm UTC

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