Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Used to reindex elasticsearch (ELK) setup for changing indexs
#!/usr/bin/env python
import elasticsearch
import elasticsearch.helpers
elasticSource = elasticsearch.Elasticsearch([{"host": "localhost", "port": 9200}])
elasticDestination = elasticsearch.Elasticsearch([{"host": "localhost", "port": 9200}])
# Setup source and destinations connection to Elasticsearch. Could have been different clusters
# Delete index so we know it doesn't exist.
elasticDestination.indices.delete(index="index_destination", ignore=[400, 404])
# Create index with nothing in it.
elasticDestination.indices.create(index="index_source", ignore=[400, 404])
elasticsearch.helpers.reindex(client=elasticSource, source_index="index_source", target_index="index_destination", target_client=elasticDestination)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.