# Help with reindex() function

**URL:** <https://discuss.elastic.co/t/help-with-reindex-function/180587>\
**Category:** Elasticsearch\
**Created:** [May 10, 2019, 4:01pm UTC](https://discuss.elastic.co/t/help-with-reindex-function/180587 "2019-05-10T16:01:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergio\_Peral\_Aguiler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergio_peral_aguiler/32/45999_2.png) [@Sergio\_Peral\_Aguiler](https://discuss.elastic.co/u/Sergio_Peral_Aguiler)\
**Post date:** [May 10, 2019, 4:01pm UTC](https://discuss.elastic.co/t/help-with-reindex-function/180587/1 "2019-05-10T16:01:49Z")

</div>

Hi Elastic team,

I'm trying to make a Python reindexing script using the Elasticsearch library, but I'm not sure how `reindex()` function should be used.  
The script would be executed by typing: `python auto_reindex YYYY.MM.DD`, as you see, expecting `date`, because my indices are called `xxxxxxx-YYY.MM.DD`.

This is how I created the Elasticsearch object: `es = Elasticsearch({"host": "localhost", "port": 9200})`. My Elasticserach is running at port 9200.

I'm getting an error at the following line:

`es.reindex(body='{"source":{"index":"original-index-{0}"},"dest":{"index":"temporary-index-{0}"}}'.format(date))`

The error I'm getting is:

> Traceback (most recent call last):  
> File "auto\_reindex\_test", line 20, in   
> es.reindex(body='{"source":{"index":"original-index-{0}"},"dest":{"index":"temporary-index-{0}"}}'.format(date))  
> KeyError: '"source"'

I'm sure I'm doing something wrong but I don't know what it is. Could someone tell me how should I properly create my Elasticsearch object if I'm doing it wrong, or how to use the function `reindex()` to reindex the index `xxxxxx-YY.MM.DD` into `xxxxxx-tmp-YY.MM.DD`?

Some help would be really appreciated.

Best regards,  
Sergio.

---

<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:** [June 7, 2019, 4:01pm UTC](https://discuss.elastic.co/t/help-with-reindex-function/180587/2 "2019-06-07T16:01:49Z")

</div>

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