import json import random import string from datetime import datetime from elasticsearch import Elasticsearch, helpers es = Elasticsearch() doc = [ { 'index':{ '_index': "new", '_id' : "123", '_type':"zhangdahe" } }, { 'delete': { "_index": "company_base_info_2", "_type": "company_info", '_id':"83tEbm4B0FXiLewuY5Jr" } } ] docs_as_string = json.dumps(doc[0]) + '\n' + json.dumps(doc[1]) + '\n' ss = es.bulk(body=docs_as_string) print(ss)