# Is reindex from remote included in Python client

**URL:** <https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814>\
**Category:** Elasticsearch\
**Created:** [October 11, 2023, 11:39am UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814 "2023-10-11T11:39:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shahab\_Malekzadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahab_malekzadeh/32/126447_2.png) [@Shahab\_Malekzadeh](https://discuss.elastic.co/u/Shahab_Malekzadeh)\
**Post date:** [October 11, 2023, 11:39am UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/1 "2023-10-11T11:39:15Z")

</div>

The Elasticsearch documentation specify the ability to reindex from remote. Can this be done through Python client? I can't find any example. This is what I got which returns error:

host = '[https://XXXXXXXXX](https://XXXXXXXXX)'  
indexname = 'my\_index'  
dest\_index = 'my dest index'

query = {  
"source": {  
"remote": {  
"host": host  
},  
"index": indexname  
},  
"dest": {  
"index": dest\_index  
}  
}  
result = es.reindex(query, wait\_for\_completion=True, request\_timeout=10000)

elasticsearch.exceptions.RequestError: RequestError(400, 'x\_content\_parse\_exception', '[1:172] [reindex] failed to parse field [source]')

The reindex works without the remote key in the source.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![iulia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iulia/32/124658_2.png) [@iulia](https://discuss.elastic.co/u/iulia)\
**Post date:** [October 11, 2023, 2:15pm UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/2 "2023-10-11T14:15:01Z")

</div>

Hi Shahab, welcome to the community!  
The reindex function is indeed implemented for the python client, you can [see it in the docs here.](https://elasticsearch-py.readthedocs.io/en/stable/api.html#elasticsearch.Elasticsearch.reindex)where it also mentions this can help you fetch documents from a remote cluster as well.

Does the reindex query you are using work when sending it directly to the dev console? Then we can see if it is a query issue or something specific to the python client implementation.

Just to double check the cluster is whitelisted:

- If reindexing from a remote cluster, you must explicitly allow the remote host in the `reindex.remote.whitelist` setting of `elasticsearch.yml`. See [Reindex from remote](https://www.elastic.co/guide/en/elasticsearch/reference/8.10/docs-reindex.html#reindex-from-remote).

Also, what kind of authentication method are you using for the remote cluster? Can you try adding the username / password in the host part of the request as well?

Hope this helps!  
Cheers,  
Iulia

---

<div class="post-metadata">

**Author:** ![Shahab\_Malekzadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahab_malekzadeh/32/126447_2.png) [@Shahab\_Malekzadeh](https://discuss.elastic.co/u/Shahab_Malekzadeh)\
**Post date:** [October 11, 2023, 2:34pm UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/3 "2023-10-11T14:34:31Z")

</div>

Hi iulia,  
I get the same error when I try it directly in dev tool. I am running some test if the reindex from remote could be used for our production cluster reindexing. In my test the host is the same as my destination cluster. I tried the username/password but get the same error message.  
Thanks

Shahab

---

<div class="post-metadata">

**Author:** ![iulia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iulia/32/124658_2.png) [@iulia](https://discuss.elastic.co/u/iulia)\
**Post date:** [October 11, 2023, 4:09pm UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/4 "2023-10-11T16:09:26Z")

</div>

I think in this case snapshot and restore (instead of reindex) would be better fitted. It would be faster in terms of performance, not to mention have the extra benefit of the backup feature, especially if you're looking at this for a production environment.

Have you looked into this option as well? [See docs here.](https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html#snapshot-restore-warnings)

You can implement this in python as well - [see docs](https://elasticsearch-py.readthedocs.io/en/v8.10.0/api.html?highlight=snapshot%20create#snapshots)

And [this answer](https://stackoverflow.com/questions/41215243/can-anyone-give-a-snapshot-example-of-elastic-search-by-using-python) is a bit old but can be a good start for the format.

---

<div class="post-metadata">

**Author:** ![Shahab\_Malekzadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahab_malekzadeh/32/126447_2.png) [@Shahab\_Malekzadeh](https://discuss.elastic.co/u/Shahab_Malekzadeh)\
**Post date:** [October 12, 2023, 6:47am UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/5 "2023-10-12T06:47:51Z")

</div>

Thank lulia, much appreciate your help.  
Would snapshot restore upgrade the version of the indexes?  
Some of our indexes are version 6.7 and we need them to be upgraded hence we are looking at the re indexing .  
Thanks  
Shahab

---

<div class="post-metadata">

**Author:** ![iulia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iulia/32/124658_2.png) [@iulia](https://discuss.elastic.co/u/iulia)\
**Post date:** [October 12, 2023, 11:04am UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/6 "2023-10-12T11:04:25Z")

</div>

Depends on the versions you're upgrading from and to, we have a table showing the compatibilities here:

> **[Snapshot and restore | Elasticsearch Guide \[8.10\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html#snapshot-index-compatibility)**

You cannot use the snapshot to restore back to an earlier version, only moving forward.  
From 6.7 you should be able to use this method to upgrade to 6.8  
7.0–7.1, 7.2–7.17. or 8.3-8.10.

---

<div class="post-metadata">

**Author:** ![Shahab\_Malekzadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahab_malekzadeh/32/126447_2.png) [@Shahab\_Malekzadeh](https://discuss.elastic.co/u/Shahab_Malekzadeh)\
**Post date:** [October 12, 2023, 11:33am UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/7 "2023-10-12T11:33:35Z")

</div>

Many thanks iulia. I will try this method.

Shahab

---

<div class="post-metadata">

**Author:** ![iulia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iulia/32/124658_2.png) [@iulia](https://discuss.elastic.co/u/iulia)\
**Post date:** [October 12, 2023, 1:46pm UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/8 "2023-10-12T13:46:04Z")

</div>

you're welcome! hope it works, otherwise you'll find us here 🙂

---

<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 9, 2023, 1:46pm UTC](https://discuss.elastic.co/t/is-reindex-from-remote-included-in-python-client/344814/9 "2023-11-09T13:46:34Z")

</div>

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