在Python中将CSV索引到ElasticSearch
发布时间:2020-12-20 13:02:42 所属栏目:Python 来源:网络整理
导读:希望将CSV文件索引到ElasticSearch,而不使用Logstash. 我正在使用elasticsearch-dsl高级库. 给定带标题的CSV,例如: name,address,urladam,hills 32,http://rockit.comjane,valleys 23,http://popit.com 按字段索引所有数据的最佳方法是什么?最终我想让每一
希望将CSV文件索引到ElasticSearch,而不使用Logstash.
我正在使用elasticsearch-dsl高级库. 给定带标题的CSV,例如: name,address,url adam,hills 32,http://rockit.com jane,valleys 23,http://popit.com 按字段索引所有数据的最佳方法是什么?最终我想让每一行看起来像这样 { "name": "adam","address": "hills 32","url": "http://rockit.com" } 解决方法
使用较低级别的elasticsearch-py库,这种任务更容易:
from elasticsearch import helpers,Elasticsearch import csv es = Elasticsearch() with open('/tmp/x.csv') as f: reader = csv.DictReader(f) helpers.bulk(es,reader,index='my-index',doc_type='my-type') (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |