码迷,mamicode.com
首页 > 其他好文 > 详细

Elasticsearch --- 向es中导入数据

时间:2019-05-24 22:25:27      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:文件导入   arc   article   导入   数据   doc   open   enc   tags   

一.从文件导入(用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中导入数据

标签:文件导入   arc   article   导入   数据   doc   open   enc   tags   

原文地址:https://www.cnblogs.com/sc-1067178406/p/10920435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!