Skip to content

Commit

Permalink
add optional host and path param on load.py (elastic#601)
Browse files Browse the repository at this point in the history
If you want/need to load data into a different es cluster just specify either the
 * -H/--host option
 * -p/--path option

ex: python load.py --host http://123.123.123.123:9200 -p /home/code/elasticsearch
  • Loading branch information
rciorba authored and honzakral committed Jun 15, 2017
1 parent 2802269 commit d9db39a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions example/load.py
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime
import logging
import sys
import argparse

import git

Expand Down Expand Up @@ -174,11 +175,25 @@ def load_repo(client, path=None, index='git'):
tracer.setLevel(logging.INFO)
tracer.addHandler(logging.FileHandler('/tmp/es_trace.log'))

parser = argparse.ArgumentParser()
parser.add_argument(
"-H", "--host",
action="store",
default="localhost:9200",
help="The elasticsearch host you wish to connect too. (Default: localhost:9200)")
parser.add_argument(
"-p", "--path",
action="store",
default=None,
help="Path to git repo. Commits used as data to load into Elasticsearch. (Default: None")

args = parser.parse_args()

# instantiate es client, connects to localhost:9200 by default
es = Elasticsearch()
es = Elasticsearch(args.host)

# we load the repo and all commits
load_repo(es, path=sys.argv[1] if len(sys.argv) == 2 else None)
load_repo(es, path=args.path)

# run the bulk operations
success, _ = bulk(es, REPO_ACTIONS, index='git', raise_on_error=True)
Expand Down

0 comments on commit d9db39a

Please sign in to comment.