版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Areigninhell/article/details/84401381
es_client = Elasticsearch(["localhost:9200"])
创建索引
es_client.indices.create(index='log_index', ignore=400)
创建索引(如果此索引不存在则会创建)并且插入数据
body = {"func_info":"删除日志", "error_info":"id为空", "write_date":datetime.datetime.now()}
创建索引(如果此索引不存在则会创建)并且可以批量插入数据,此效率比较高
body1 = {"func_info":"删除日志", "error_info":"id为空", "write_date":datetime.datetime.now()}
body2 = {"func_info":"删除日志", "error_info":"id为空", "write_date":datetime.datetime.now()}
result = [{'index': {'_index': 'log_index', '_type': 'log_index'}}, body1,{'index': {'_index': 'log_index', '_type': 'log_index'}}, body2]
es_result = es_client.bulk(index="log_index",doc_type="log_index", body= result)