ElasticSearch对文本的搜索速度真的是神速呀,基本是毫秒级别的。对于大文本,简直就是秒飞MYSQL十条街。使用python实现:
es = Elasticsearch(['10.18.6.26:9200']) ret = collection.find({}) # 删除mongo的_id字段,否则无法把Object类型插入到Elastic map(lambda x:(del x['_id']),ret) actions= for idx,item in enumerate(ret): i={ "_index":"jsl", "_type":"text", "_id":idx, "_source":{ # 需要提取的字段 "title":item.get('title'), "url":item.get('url') } } actions.append(i) start=time.time() helpers.bulk(es,actions) end=time.time()-start print(end)
运行下来,20W条数据,大概用了15秒左右全部导入ElasticSearch 数据库中。
原文出处:30daydo -> http://30daydo.com/article/367