Created
January 6, 2012 07:09
-
-
Save dlemphers/1569468 to your computer and use it in GitHub Desktop.
Simple (and greedy) reindexer
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
#!/usr/bin/env python | |
from pyes import * | |
import argparse | |
import logging | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--source', type=str, help='Enter the source index', required=True) | |
parser.add_argument('--dest', type=str, help='Enter the dest index', required=True) | |
parser.add_argument('--type', type=str, help='Enter the type', required=True) | |
parser.add_argument('--es_server', type=str, help='Enter the address of the ES server', default='127.0.0.1:9200', required=False) | |
args = parser.parse_args() | |
logging.basicConfig(level='INFO') | |
conn = ES(args.es_server) | |
count = conn.count(MatchAllQuery(), args.source, args.type)['count'] | |
logging.info('{0} {1}'.format(count, args.type)) | |
results = conn.search(MatchAllQuery(), indices=args.source, doc_types=args.type, size=count) | |
logging.info('Grabbed {0} {1}'.format(len(results), args.type)) | |
for result in results: | |
del result['meta'] | |
conn.index(result, args.dest, args.type) | |
logging.info('Done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment