peer_id.py: fix query check

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-05-27 09:22:40 +02:00
parent 4f3ccd269e
commit c1ff90f5e9
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020

View File

@ -75,21 +75,21 @@ def main():
body['query']['bool']['must_not'] = { 'exists': { 'field': 'peer_id' } } body['query']['bool']['must_not'] = { 'exists': { 'field': 'peer_id' } }
for index in indices: for index in indices:
resp = es.count(index=index, body=body) resp = es.count(index=index, body=body)
count = resp.get('count') count = resp.get('count')
print('{:22} count: {:6}'.format(index, count)) print('{:22} count: {:6}'.format(index, count))
if opts.query > 0: if opts.query and count > 0:
resp = es.search(index=index, body=body) resp = es.search(index=index, body=body)
#print_logs(resp['hits']['hits']) #print_logs(resp['hits']['hits'])
elif opts.update and count > 0: elif opts.update and count > 0:
# add the script for extracting peer_id # add the script for extracting peer_id
body['script'] = { 'lang': 'painless', 'inline': PAINLESS_SCRIPT } body['script'] = { 'lang': 'painless', 'inline': PAINLESS_SCRIPT }
try: try:
rval = es.update_by_query(index=index, body=body) rval = es.update_by_query(index=index, body=body)
except Exception as ex: except Exception as ex:
print(json.dumps(ex.info, indent=2)) print(json.dumps(ex.info, indent=2))
print('{:22} Updated: {:10} Failed: {}'.format(index, rval['updated'], rval.get('failed', 0))) print('{:22} Updated: {:10} Failed: {}'.format(index, rval['updated'], rval.get('failed', 0)))
if __name__ == '__main__': if __name__ == '__main__':
main() main()