title: Renaming fields to new index in Elasticsearch
body: <p>I have an index with this mapping:</p>
  
  <pre><code>curl -XPUT 'http://localhost:9200/origindex/_mapping/page' -d '
     {
      "page" : {
          "properties" : {
              "title" : {"type" : "text"},
              "body" : {"type" : "text"},
              "other": {"type": "text"}
          }
       }
     }'
  </code></pre>
  
  <p>In a new index, I want to copy "title" to "title1" and "title2", and "body" to "body1" and "body2" (disregarding "other"), and change the type from "page" to "articles_eng".  The new index has this mapping:</p>
  
  <pre><code>curl -XPUT 'http://localhost:9200/newindex/_mapping/articles_eng' -d '                             
  {                                                                                                  
      "articles_eng" : {                                                                             
          "properties" : {                                                                           
              "title1" : {                                                                     
                   "type" : "text",                                                                  
                   "analyzer" : "my_analyzer1"                                                    
               },                                                                                     
              "title2" : {                                                                   
                   "type" : "text",                                                                  
                   "analyzer": "my_analyzer2"                                                    
               },                                                                                     
              "body1": {                                                                       
                  "type" : "text",                                                                  
                  "analyzer": "my_analyzer1"                                                     
              },                                                                                     
              "body2" : {                                                                     
                  "type" : "text",                                                                  
                  "analyzer": "my_analyzer2" 
              }                                                   
          }                                                                                      
      }                                                                                          
  }'                                                                                              
  </code></pre>
  
  <p>From looking at <a href="https://stackoverflow.com/questions/40607350/renaming-fields-in-elasticsearch">this answer</a> and the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html" rel="nofollow noreferrer">Elasticsearch reindex docs</a> I come up with something like this:</p>
  
  <pre><code>curl -XPOST http://localhost:9200/_reindex -d '{                                                   
      "source": {                                                                                    
          "index": "origindex",                                                                          
          "type": "page",                                                                            
          "query": {                                                                                 
             "match_all": {}                                                                         
          },                                                                                         
          "_source": [ "title", "body" ]                                                             
      },                                                                                             
      "dest": {                                                                                      
          "index": "newindex"                                                                        
      },                                                                                             
      "script": {                                                                                    
          "inline": "ctx._type = \"articles_eng\"";                                                  
                    "ctx._title1 = ctx._source._title";                                         
                    "ctx._title2 = ctx._source._title";                                       
                    "ctx._body1 = ctx._source._body";                                          
                    "ctx._body2 = ctx._source._body"                                                                                                   
      }                                                                                              
  }'
  </code></pre>
  
  <p>I'm having trouble with the script lines.  If I do only the top line (changing the document type), everything works fine.  If I add the rest of the lines, I get an error </p>
  
  <blockquote>
    <p>"[reindex] failed to parse field [script]"</p>
  </blockquote>
  
  <p>caused by </p>
  
  <blockquote>
    <p>"Unexpected character (';' (code 59)): was expecting comma to separate
    Object entries\n at [Source:
    org.elasticsearch.transport.netty4.ByteBufStreamInput@37649463; line:
    14, column: 50]"</p>
  </blockquote>
  
  <p>Even if I can sort out the issue with the multiple statements, putting in just the second line gives me the error</p>
  
  <blockquote>
    <p>"Invalid fields added to context [title1]"}]</p>
  </blockquote>
  
  <p>Can anyone help me out?  It seems like this shouldn't be impossible to do.</p>