Elasticsearch --- 向es中导入数据
Posted sc-1067178406
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Elasticsearch --- 向es中导入数据相关的知识,希望对你有一定的参考价值。
一.从文件导入(用django启动)
def zi_dr(request): f = open(‘c.txt‘, ‘r‘, encoding=‘utf-8‘) action = [ { "_index": "c12", "_type": "doc", "_source": { "title": i.strip(), # 去掉 空 } } for i in f] s = time.time() helpers.bulk(es, action) print(time.time() - s) return HttpResponse("ok")
二. 从数据库中导入(用django启动)
def es2(request):
query_obj = models.Article.objects.all() action = ( { "_index": "s18", "_type": "doc", "_source": { "title": i.title, "summary": i.summary, "a_url": i.a_url, "img_url": i.img_url, "tags": i.tags } } for i in query_obj) # print(action, next(action)) import time s = time.time() helpers.bulk(es, action) print(time.time() - s) return HttpResponse(‘OK‘)
以上是关于Elasticsearch --- 向es中导入数据的主要内容,如果未能解决你的问题,请参考以下文章