Skip to content

Instantly share code, notes, and snippets.

@xamox
Last active April 6, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xamox/b9cd23d3834a03a1089af41dbf1ed6e6 to your computer and use it in GitHub Desktop.
Save xamox/b9cd23d3834a03a1089af41dbf1ed6e6 to your computer and use it in GitHub Desktop.
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