5 http = urllib3.PoolManager()
8 def _request(method, url, creds=None, body=None):
9 headers = urllib3.make_headers(basic_auth=creds)
10 return http.request(method, url, headers=headers, body=body)
13 def _post(url, creds=None, body=None):
14 return _request('POST', url, creds=creds, body=body)
17 def _get(url, creds=None, body=None):
18 return json.loads(_request('GET', url, creds=creds, body=body).data)
21 def delete_docs(url, creds=None, body=None):
22 return _request('DELETE', url, creds=creds, body=body)
25 def publish_docs(url, creds=None, body=None):
26 result = _post(url, creds=creds, body=(json.dumps(body)))
27 return result.status, result.data
30 def _get_docs_nr(url, creds=None, body=None):
31 res_data = _get('{}/_search?size=0'.format(url), creds=creds, body=body)
32 print type(res_data), res_data
33 return res_data['hits']['total']
36 def get_docs(url, creds=None, body=None, field='_source'):
38 docs_nr = _get_docs_nr(url, creds=creds, body=body)
39 res_data = _get('{}/_search?size={}'.format(url, docs_nr),
40 creds=creds, body=body)
43 for hit in res_data['hits']['hits']:
44 docs.append(hit[field])