Skip to content

Commit 9320ee7

Browse files
fxdgearhonzakral
authored andcommitted
add optional host and path param on load.py (#601)
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
1 parent 2416982 commit 9320ee7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

example/load.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from datetime import datetime
77
import logging
88
import sys
9+
import argparse
910

1011
import git
1112

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

178+
parser = argparse.ArgumentParser()
179+
parser.add_argument(
180+
"-H", "--host",
181+
action="store",
182+
default="localhost:9200",
183+
help="The elasticsearch host you wish to connect too. (Default: localhost:9200)")
184+
parser.add_argument(
185+
"-p", "--path",
186+
action="store",
187+
default=None,
188+
help="Path to git repo. Commits used as data to load into Elasticsearch. (Default: None")
189+
190+
args = parser.parse_args()
191+
177192
# instantiate es client, connects to localhost:9200 by default
178-
es = Elasticsearch()
193+
es = Elasticsearch(args.host)
179194

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

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

0 commit comments

Comments
 (0)