# Reindexing using same fields

**URL:** <https://discuss.elastic.co/t/reindexing-using-same-fields/89340>\
**Category:** Elasticsearch\
**Created:** [June 14, 2017, 9:08am UTC](https://discuss.elastic.co/t/reindexing-using-same-fields/89340 "2017-06-14T09:08:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinay\_khandelwal](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vinay\_khandelwal](https://discuss.elastic.co/u/vinay_khandelwal)\
**Post date:** [June 14, 2017, 9:08am UTC](https://discuss.elastic.co/t/reindexing-using-same-fields/89340/1 "2017-06-14T09:08:20Z")

</div>

Hello,

I am trying to reindex a large index into a smaller one by filtering . However I would like to retain some of the metadata with a different field name then used in the original index. "\_source" allows me to copy over fields as it is. How can have some of the fields renamed while reindexing?

```
POST _reindex
{
  "source": {
    "index": ["logstash-2016.09.11","logstash-2016.09.12"],
    "_source": ["_type","timestamp","machid"],
     "query": {
      "term": {
        "_type": "DCA_OBC"
      }
    }
  },
  "dest": {
    "index": "docs_a"
  },
   "script": {
    "inline": "ctx._source.gid = doc[_id]",
    "lang": "painless"
  }
}

```

Can I use the painless script in similar form as shown above, to achieve the same? Here gid is the new field name to store the \_id of previous index. I want to give this document a new id on reindexing and save the previous one as gid too.

Thanks

---

<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 12, 2017, 9:17am UTC](https://discuss.elastic.co/t/reindexing-using-same-fields/89340/2 "2017-07-12T09:17:26Z")

</div>

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