Migration of 2.3 indices to 5.6 using Painless


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:

"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?

correct instantiation of the inner object is done via:

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

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