# Reindex with Scan-scroll and bulk\_API

**URL:** <https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379>\
**Category:** Elasticsearch\
**Created:** [September 30, 2015, 5:59am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379 "2015-09-30T05:59:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![krish0608](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krish0608/32/6797_2.png) [@krish0608](https://discuss.elastic.co/u/krish0608)\
**Post date:** [September 30, 2015, 5:59am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/1 "2015-09-30T05:59:44Z")

</div>

I need to reindex my data. I was able to get a scroll\_id using the scan and scroll API. Now I need to insert those data to my new index, but can't figure out how to use the bulk API to do this.

Please Give some Example.

---

<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:** [September 30, 2015, 6:17am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/2 "2015-09-30T06:17:20Z")

</div>

Did you read this? [https://www.elastic.co/guide/en/elasticsearch/guide/current/bulk.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/bulk.html)

---

<div class="post-metadata">

**Author:** ![krish0608](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krish0608/32/6797_2.png) [@krish0608](https://discuss.elastic.co/u/krish0608)\
**Post date:** [September 30, 2015, 6:26am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/3 "2015-09-30T06:26:59Z")

</div>

Thanxs..!!!but i have read this but not getting exact result.

PUT /my\_index\_1  
PUT /my\_index\_1/\_mapping/data  
{ "data":{"properties":{ "counter":{"type":"string"}}}  
}  
PUT /my\_index\_1/data/2  
{  
"counter":2  
}  
GET /my\_index\_1/\_mapping  
GET /my\_index\_1/\_search

POST /\_aliases  
{  
"actions": [  
{ "remove": {  
"alias": "my\_index\_docs",  
"index": "my\_index\_1"  
}},  
{ "add": {  
"alias": "my\_index\_docs",  
"index": "my\_index\_2"  
}}  
]  
}

PUT /my\_index\_2

PUT /my\_index\_2/\_mapping/test  
{  
"test":{"properties": { "counter":{"type":"long"}  
}}  
}

GET /my\_index\_2/test/\_search  
GET /my\_index\_2/\_mapping

This is my code.and problem is that am not getting new mapping or data in my\_index\_2 my new index....please help me out.

---

<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:** [September 30, 2015, 6:47am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/4 "2015-09-30T06:47:17Z")

</div>

I don't see in your example when you read data from the first index and then bulk in the second one.

---

<div class="post-metadata">

**Author:** ![krish0608](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krish0608/32/6797_2.png) [@krish0608](https://discuss.elastic.co/u/krish0608)\
**Post date:** [September 30, 2015, 6:49am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/5 "2015-09-30T06:49:58Z")

</div>

how to bulk data in new index.i am new in elasticsearch..please help me out

---

<div class="post-metadata">

**Author:** ![krish0608](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krish0608/32/6797_2.png) [@krish0608](https://discuss.elastic.co/u/krish0608)\
**Post date:** [September 30, 2015, 7:03am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/6 "2015-09-30T07:03:24Z")

</div>

> [@dadoonet](#):
>
> example when you read data from the first index and then bulk in the second one.

can you give me some example of when you read data from the first index and then bulk in the second one.

---

<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:** [September 30, 2015, 7:42am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/7 "2015-09-30T07:42:57Z")

</div>

> [@krish0608](#):
>
> can you give me some example of when you read data from the first index and then bulk in the second one.

Well. Not really.

I think that it mostly depends on your technology (Java, PHP, Python... whatever).  
Almost all clients (but Java) already have a reindex method.

Here is an example on how I'm doing it using Logstash: [https://david.pilato.fr/blog/2015-05-20-reindex-elasticsearch-with-logstash/](http://david.pilato.fr/blog/2015/05/20/reindex-elasticsearch-with-logstash/) but I guess you are looking for something else.

You said that:

> [@krish0608](#):
>
> I was able to get a scroll\_id using the scan and scroll API.

Then on the client side, you have to prepare a bulk request which does what you need and send it.

```
POST /_bulk
{ "index": { "_index": "my_index_2", "_type": "test" }}
{ your doc 1 here" }
{ "index": { "_index": "my_index_2", "_type": "test" }}
{ your doc 2 here" }
{ "index": { "_index": "my_index_2", "_type": "test" }}
{ your doc 3 here" }

```

---

<div class="post-metadata">

**Author:** ![krish0608](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krish0608/32/6797_2.png) [@krish0608](https://discuss.elastic.co/u/krish0608)\
**Post date:** [September 30, 2015, 9:13am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/8 "2015-09-30T09:13:18Z")

</div>

sorry,this is not my problem...Actually I want to change my mapping of existing data.  
please go through this link.Is It possible change mapping of existing data??

> **[Changing Mapping with Zero Downtime
	  	 | Elastic](https://www.elastic.co/blog/changing-mapping-with-zero-downtime)**
>
> Update November 2, 2015: Make sure to check out the updates with Elasticsearch mappings introduced in the 2.0 release.Update May 1, 2017: This blog was originally published several major versions...

PUT /my\_index\_1  
PUT /my\_index\_1/\_mapping/data  
{ "data":{"properties":{ "counter":{"type":"string"}}}  
}  
PUT /my\_index\_1/data/2  
{  
"counter":2  
}  
GET /my\_index\_1/\_mapping  
GET /my\_index\_1/\_search

POST /\_aliases  
{  
"actions": [  
{ "remove": {  
"alias": "my\_index\_docs",  
"index": "my\_index\_1"  
}},  
{ "add": {  
"alias": "my\_index\_docs",  
"index": "my\_index\_2"  
}}  
]  
}

PUT /my\_index\_2

PUT /my\_index\_2/\_mapping/test  
{  
"test":{"properties": { "counter":{"type":"long"}  
}}  
}

GET /my\_index\_2/test/\_search  
GET /my\_index\_2/\_mapping

---

<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:** [September 30, 2015, 9:44am UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/9 "2015-09-30T09:44:07Z")

</div>

So the blog post I linked totally answers to this question.

Also in the link you just pasted, here is what is written:

> Then, pull the documents in from your old index, using a scrolled search and index them into the new index using the `bulk API`. Many of the client APIs provide a `reindex()` method which will do all of this for you. Once you are done, you can delete the old index.

This is exactly what I meant with my previous answers...

---

<div class="post-metadata">

**Author:** ![oyiadom](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@oyiadom](https://discuss.elastic.co/u/oyiadom)\
**Post date:** [October 7, 2015, 1:09pm UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/10 "2015-10-07T13:09:45Z")

</div>

@krish0608 It is my understanding that if you want to change the mapping of an index, you need to create a new index with the desired mapping and then index your data into the new index. In other words, you cannot change the mapping of an index that already has data in it.

---

<div class="post-metadata">

**Author:** ![telebh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/telebh/32/42272_2.png) [@telebh](https://discuss.elastic.co/u/telebh)\
**Post date:** [March 6, 2017, 9:19pm UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/11 "2017-03-06T21:19:08Z")

</div>

Hi there,

I am nebiew to Elasticsearch, and try to re-index data for existing index using scroll & bulk api but bulk api does not work for me

i have tried scroll as per url below, but not sure how to index the returned documents in new index which contains the new index mappings? any idea?  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html)

---

<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 5, 2017, 10:02pm UTC](https://discuss.elastic.co/t/reindex-with-scan-scroll-and-bulk-api/31379/12 "2017-07-05T22:02:31Z")

</div>


