Created
May 14, 2013 23:32
-
-
Save ConsoleCatzirl/5580576 to your computer and use it in GitHub Desktop.
elasticsearch migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import logging | |
logging.basicConfig(format='%(asctime)s\t%(name)-16s %(levelname)-8s %(message)s') | |
#very noisy library | |
requests_log = logging.getLogger("requests") | |
requests_log.setLevel(logging.WARNING) | |
logger = logging.getLogger('es_migrate') | |
logger.setLevel(logging.INFO) | |
local_es_host = 'localhost' | |
local_es_port = '9200' | |
remote_es_host = 'logstash.example.net' | |
remote_es_port = '9200' | |
mapping = requests.get('http://{0}:{1}/_mapping'.format(remote_es_host, remote_es_port)).json() | |
indices = mapping.keys() | |
for index in indices: | |
logger.info('Index: {0}'.format(index)) | |
for type in mapping[index]: | |
logger.info('Type: {0}'.format(type)) | |
url = ('http://{0}:{1}/{2}/{3}/_reindex?searchHost={4}&searchPort={5}' | |
.format(local_es_host, local_es_port, index, type, remote_es_host, remote_es_port)) | |
logger.debug(url) | |
requests.put(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment