5 http = urllib3.PoolManager()
8 def delete_request(url, creds, body=None):
9 headers = urllib3.make_headers(basic_auth=creds)
10 http.request('DELETE', url, headers=headers, body=body)
13 def publish_json(json_ojb, creds, to):
14 json_dump = json.dumps(json_ojb)
19 headers = urllib3.make_headers(basic_auth=creds)
20 result = http.request('POST', to, headers=headers, body=json_dump)
21 return result.status, result.data
24 def _get_nr_of_hits(elastic_json):
25 return elastic_json['hits']['total']
28 def get_elastic_docs(elastic_url, creds, body=None, field = '_source'):
30 # 1. get the number of results
31 headers = urllib3.make_headers(basic_auth=creds)
32 elastic_json = json.loads(http.request('GET', elastic_url + '/_search?size=0', headers=headers, body=body).data)
34 nr_of_hits = _get_nr_of_hits(elastic_json)
37 elastic_json = json.loads(http.request('GET', elastic_url + '/_search?size={}'.format(nr_of_hits), headers=headers, body=body).data)
40 for hit in elastic_json['hits']['hits']:
41 elastic_docs.append(hit[field])
45 def get_elastic_docs_by_days(elastic_url, creds, days):
63 raise Exception('Update days must be non-negative')
64 return get_elastic_docs(elastic_url, creds, body)