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)

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code