# How can we reindex with existing documents to a new type along with already existing types using painless

**URL:** <https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085>\
**Category:** Elasticsearch\
**Created:** [October 26, 2018, 3:21am UTC](https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085 "2018-10-26T03:21:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivaprasad](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shivaprasad](https://discuss.elastic.co/u/Shivaprasad)\
**Post date:** [October 26, 2018, 3:21am UTC](https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085/1 "2018-10-26T03:21:06Z")

</div>

In an index I have 3 types type A, type B, type C along with their properties,  
I have to reindex with a new type D using painless.

I am using Elasticsearch version 5.6.9

---

<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:** [October 26, 2018, 10:37am UTC](https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085/2 "2018-10-26T10:37:16Z")

</div>

May be I did not get the question but you don't need painless for that:

```auto
POST _reindex
{
  "source": {
    "index": "twitter",
    "type": "a",
  },
  "dest": {
    "index": "new_twitter",
    "type": "_doc"
  }
}

```

```auto
POST _reindex
{
  "source": {
    "index": "twitter",
    "type": "b",
  },
  "dest": {
    "index": "new_twitter",
    "type": "_doc"
  }
}

```

```auto
POST _reindex
{
  "source": {
    "index": "twitter",
    "type": "c",
  },
  "dest": {
    "index": "new_twitter",
    "type": "_doc"
  }
}

```

Note that in 6.x you are not allowed anymore to create indices with multiple types so it's better to be prepared for that and to start a new index instead.

---

<div class="post-metadata">

**Author:** ![Shivaprasad](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shivaprasad](https://discuss.elastic.co/u/Shivaprasad)\
**Post date:** [October 26, 2018, 3:11pm UTC](https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085/3 "2018-10-26T15:11:07Z")

</div>

Sorry I didn't explain it properly,  
below if we see we have \_type = exams and we have studentUid = 112546  
{  
"took": 7,  
"timed\_out": false,  
"\_shards": {  
"total": 10,  
"successful": 10,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 597680,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "dev-environment",  
"\_type": "exams",  
"\_id": "112546",  
"\_score": 1,  
"\_routing": "689",  
"\_source": {

```
      "studentUid": "112546",
      "isValid": true

```

So now if I reindex I want \_type = student with studentUid = 112546 as property (value comes from exams type) using painless script something like this below.

```
	  {

```

"took": 7,  
"timed\_out": false,  
"\_shards": {  
"total": 10,  
"successful": 10,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 597680,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "dev-environment",  
"\_type": "student",  
"\_id": "112546",  
"\_score": 1,  
"\_routing": "689",  
"\_source": {

```
      "studentUid": "112546",
      "isValid": true
	  }

```

I went through Reindex api ([https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html)) and also \_type field api ([https://www.elastic.co/guide/en/elasticsearch/reference/5.4/mapping-type-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/mapping-type-field.html)) but nowhere they have mentioned reindexing to a new \_type ( student ) with property values taking from existing \_type (exams) existing

---

<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:** [October 26, 2018, 3:32pm UTC](https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085/4 "2018-10-26T15:32:19Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Did you try what I shared?

```auto
POST _reindex
{
  "source": {
    "index": "dev-environment",
    "type": "exams",
  },
  "dest": {
    "index": "new_dev-environment",
    "type": "student"
  }
}

```

---

<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:** [November 23, 2018, 3:32pm UTC](https://discuss.elastic.co/t/how-can-we-reindex-with-existing-documents-to-a-new-type-along-with-already-existing-types-using-painless/154085/5 "2018-11-23T15:32:21Z")

</div>

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