-
Notifications
You must be signed in to change notification settings - Fork 66
/
reindex.py
executable file
·42 lines (29 loc) · 1.01 KB
/
reindex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import argparse
from elasticsearch import Elasticsearch
from annotator.reindexer import Reindexer
description = """
Reindex an elasticsearch index.
WARNING: Documents that are created while reindexing may be lost!
"""
def main():
argparser = argparse.ArgumentParser(description=description)
argparser.add_argument('old_index', help="Index to read from")
argparser.add_argument('new_index', help="Index to write to")
argparser.add_argument('--host', help="Elasticsearch server, host[:port]")
argparser.add_argument('--alias', help="Alias for the new index")
args = argparser.parse_args()
host = args.host
old_index = args.old_index
new_index = args.new_index
alias = args.alias
if host:
conn = Elasticsearch([host])
else:
conn = Elasticsearch()
reindexer = Reindexer(conn, interactive=True)
reindexer.reindex(old_index, new_index)
if alias:
reindexer.alias(new_index, alias)
if __name__ == '__main__':
main()