Skip to content

Instantly share code, notes, and snippets.

@ftfarias
Last active December 7, 2018 19:01
Show Gist options
  • Save ftfarias/3fb3e00d2e5294aa3577d96e4b098af9 to your computer and use it in GitHub Desktop.
Save ftfarias/3fb3e00d2e5294aa3577d96e4b098af9 to your computer and use it in GitHub Desktop.
elasticsearch / urllib3
import os
import json
import urllib3
url_delete = 'http://172.31.x.x:9200/my_index/_delete_by_query'
query_delete = {
"query": { "match": { "fk_xxx": day }}
}
headers = urllib3.util.make_headers(basic_auth='user:secret_password')
headers['Content-Type'] = 'application/json'
http = urllib3.PoolManager()
query_delete_json = json.dumps(query_delete).encode('utf-8')
r = http.urlopen('POST', url_delete, body=query_delete_json,
headers=headers)
es_result = json.loads(r.data.decode('utf-8'))
print(es_result)
_________________________________________________
def get_city_id(lat, lng):
URL = 'http://api.xx.com.br/getCity'
params = { "latitude": lat, "longitude": lng}
http = urllib3.PoolManager()
r = http.request('GET', URL, fields=params)
return json.loads(r.data.decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment