# \[SOLVED\] Elasticsearch python API and reindex module

**URL:** <https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105>\
**Category:** Elasticsearch\
**Created:** [October 15, 2016, 1:19pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105 "2016-10-15T13:19:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![axelfelix](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@axelfelix](https://discuss.elastic.co/u/axelfelix)\
**Post date:** [October 15, 2016, 1:19pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/1 "2016-10-15T13:19:24Z")

</div>

Hi all,

I have created a [python](https://elasticsearch-py.readthedocs.io/en/master/index.html) script able to reindex based on list of index.

My problem is the timeout and wait\_for\_completion option.

When my script launch a reindexation I have to wait until is finished otherwise the reindexation is not performed entirely. For this purpose I need to implement the right global option request\_timeout based on index sized and wait the end of the reindexation for each index.

If I put wait\_for\_completation, I raise an exception and my reindexation failed (I have an index with some kilobyte inside). If I use the timeout option in reindex module (with 5 minutes for example), it fail too (I also get a new index without all my documents inside).

So the only way for me is to use the global request\_timeout parameter with value generated depending on index size. But if my index is big, it can take a while.

In my environment, 10 indices took 30 minutes. But for the next time in need to reindex almost 200 indices so it is too long.

If somebody have an idea to play this kind of script in background or something like that.

Thanks in advance,  
Alex

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 15, 2016, 1:48pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/2 "2016-10-15T13:48:34Z")

</div>

This is a thing we fixed in 5.0, which isn't related yet. You use  
wait\_for\_completion=false and it gives you back a job. You can then http  
GET the job with wait\_for\_completion=true. If that times out you can just  
try again. The fix in 5.0 is that even if the job finishes when you aren't  
waiting it'll still return from that GET API.

---

<div class="post-metadata">

**Author:** ![axelfelix](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@axelfelix](https://discuss.elastic.co/u/axelfelix)\
**Post date:** [October 24, 2016, 12:07pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/3 "2016-10-24T12:07:55Z")

</div>

Thanks for your reply and sorry for my late answer.

It seems that if I put "wait\_for\_completion=false" during reindexation I can't make another reindexation. If I try to make a new reindexation that stop the first reindexation. It is right ? Or I did something wrong ?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 25, 2016, 5:20pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/4 "2016-10-25T17:20:45Z")

</div>

Elasticsearch doesn't mind if you have multiple reindex tasks running at one time. If they both try to write to the same place then you are going to have trouble, but that is what the \_cancel API is for. Canceling looks like:

```auto
curl -XPOST _tasks/{task_id}/_cancel

```

---

<div class="post-metadata">

**Author:** ![axelfelix](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@axelfelix](https://discuss.elastic.co/u/axelfelix)\
**Post date:** [October 26, 2016, 8:33am UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/5 "2016-10-26T08:33:24Z")

</div>

Thanks but I'm not sure that we are talking about the same subject.

When I make a reindexation with python api of one index (300mb) and the next action in my script is to reindex another index, the first reindexation stop (for the first reindexation, the new index is 3mb for example contrary to 300mb). And the second reindexation task finish correctly (if I have just 2 reindexation).

If I have 50 reindexation tasks in my script, the 49 first tasks don't work correctly, but the 50th reindexation works correctly.

I'm not sure to explain clearly my issue. So sorry about that.

Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![JoarSvensson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joarsvensson/32/8740_2.png) [@JoarSvensson](https://discuss.elastic.co/u/JoarSvensson)\
**Post date:** [October 26, 2016, 9:44am UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/6 "2016-10-26T09:44:23Z")

</div>

Have you considered using the Curator? [https://github.com/elastic/curator](https://github.com/elastic/curator)

---

<div class="post-metadata">

**Author:** ![axelfelix](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@axelfelix](https://discuss.elastic.co/u/axelfelix)\
**Post date:** [October 26, 2016, 10:00am UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/7 "2016-10-26T10:00:15Z")

</div>

Hi thanks,

I'm not sure that the curator allow reindexation.  
I will check the code anyway.

Alex

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [October 26, 2016, 2:45pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/8 "2016-10-26T14:45:55Z")

</div>

Curator is going to have reindex in 4.x (there's already a feature request for it, and I'm actively developing it), but more especially in 5.x, using the Reindex API. It will not do generic reindexing for versions of Elasticsearch without the Reindex API, which was added in Elasticsearch 2.3.

---

<div class="post-metadata">

**Author:** ![axelfelix](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@axelfelix](https://discuss.elastic.co/u/axelfelix)\
**Post date:** [October 26, 2016, 3:11pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/9 "2016-10-26T15:11:58Z")

</div>

Thanks !

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 31, 2016, 3:01pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/10 "2016-10-31T15:01:11Z")

</div>

> [@axelfelix](#):
>
> I'm not sure to explain clearly my issue. So sorry about that.

That is pretty clear. This sounds like an issue with the python API.

---

<div class="post-metadata">

**Author:** ![axelfelix](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@axelfelix](https://discuss.elastic.co/u/axelfelix)\
**Post date:** [October 31, 2016, 4:13pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/11 "2016-10-31T16:13:27Z")

</div>

Ok, 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 5, 2017, 10:08pm UTC](https://discuss.elastic.co/t/solved-elasticsearch-python-api-and-reindex-module/63105/12 "2017-07-05T22:08:12Z")

</div>


