blob: 53922a5276f1e8227a30571b2cc4b4eed56ca1bc [file] [log] [blame]
Michael Liang6fb58e42014-08-15 11:40:11 -07001# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This file will copy all data from one index into another index.
6
7
8"""This file will copy all data from one index into another index.
9
10usage: es_reindex.py [-h] [--index_old INDEX_OLD] [--index_new INDEX_NEW]
11 [--timeout TIMEOUT] [--size SIZE]
12
13optional arguments:
14 -h, --help show this help message and exit
15 --index_old INDEX_OLD
16 --index_new INDEX_NEW
17 --timeout TIMEOUT enter timeout
18 --size SIZE enter max entries to return
19
20"""
21
22
23import argparse
24
25import common
26from autotest_lib.client.common_lib.cros.graphite import es_utils
27
28
29def main():
30 """main script. """
31
32 parser = argparse.ArgumentParser()
33 parser.add_argument('--index_old', type=str, dest='index_old')
34 parser.add_argument('--index_new', type=str, dest='index_new')
35 parser.add_argument('--timeout', type=int, dest='timeout',
36 help='enter timeout', default=3)
37 parser.add_argument('--size', type=int, dest='size',
38 help='enter max entries to return',
39 default=10000000)
40 options = parser.parse_args()
41 index_old, index_new = options.index_old, options.index_new
42 host = es_utils.METADATA_ES_SERVER
43 port = es_utils.ES_PORT
44 timeout = options.timeout
45 print 'Querying ES on %s:%s \n\n' % (host, port)
46 print 'Moving from index: %s to index: %s' % (index_old, index_new)
47 query = {
48 'query' : {
49 'match_all' : {}
50 },
51 'size': options.size
52 }
53 host = es_utils.METADATA_ES_SERVER
54 port = es_utils.ES_PORT
55 print 'Querying ES on %s:%s \n\n' % (host, port)
56 print query, index_old, host, port, '\n\n'
57 result = es_utils.execute_query(query, index_old, host, port, timeout)
58 print result['hits']['total']
59 print 'created all the results :)'
60 es = es_utils.ESMetadata()
61 for hit in result['hits']['hits']:
62 metadata = hit['_source']
63 es.post(type_str=hit['_type'], metadata=metadata, index=index_new)
64 print 'done'
65
66
67if __name__ == '__main__':
68 main()