python store bin file to elasticsearch
import base64
from elasticsearch import Elasticsearch
# base64_decode_file
def base64_decode_file(file):
with open(file, 'rb') as f:
return base64.b64encode(f.read()).decode('utf-8')
# put_to_es
def put_to_es(es, index, doc_type, doc_id, body):
es.index(index=index, doc_type=doc_type, id=doc_id, body=body)
if __name__ == '__main__':
fileContent = base64_decode_file('wdd.jpg')
fileName = 'wdd.jpg'
es = Elasticsearch(['http://localhost:9200'])
put_to_es(es, 'test', 'test', fileName, fileContent)