From c1ff90f5e96e50c39e3443cc6e89a7e2bb6abaac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 27 May 2020 09:22:40 +0200 Subject: [PATCH] peer_id.py: fix query check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- elasticsearch/peer_id.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/elasticsearch/peer_id.py b/elasticsearch/peer_id.py index c3798fc..2ffb4a6 100755 --- a/elasticsearch/peer_id.py +++ b/elasticsearch/peer_id.py @@ -75,21 +75,21 @@ def main(): body['query']['bool']['must_not'] = { 'exists': { 'field': 'peer_id' } } for index in indices: - resp = es.count(index=index, body=body) - count = resp.get('count') - print('{:22} count: {:6}'.format(index, count)) + resp = es.count(index=index, body=body) + count = resp.get('count') + print('{:22} count: {:6}'.format(index, count)) - if opts.query > 0: - resp = es.search(index=index, body=body) - #print_logs(resp['hits']['hits']) - elif opts.update and count > 0: - # add the script for extracting peer_id - body['script'] = { 'lang': 'painless', 'inline': PAINLESS_SCRIPT } - try: - rval = es.update_by_query(index=index, body=body) - except Exception as ex: - print(json.dumps(ex.info, indent=2)) - print('{:22} Updated: {:10} Failed: {}'.format(index, rval['updated'], rval.get('failed', 0))) + if opts.query and count > 0: + resp = es.search(index=index, body=body) + #print_logs(resp['hits']['hits']) + elif opts.update and count > 0: + # add the script for extracting peer_id + body['script'] = { 'lang': 'painless', 'inline': PAINLESS_SCRIPT } + try: + rval = es.update_by_query(index=index, body=body) + except Exception as ex: + print(json.dumps(ex.info, indent=2)) + print('{:22} Updated: {:10} Failed: {}'.format(index, rval['updated'], rval.get('failed', 0))) if __name__ == '__main__': main()