方便从csv到elasticsearch的内容索引
esimport的Python项目详细描述
使用
索引csv文件的内容(其中第一行包含字段 名称)在ElasticSearch服务器中,必须提供-s、-f、-i和 -T参数。如果指定的索引或类型不存在于 指定的ElasticSearch服务器,它将在 执行。下面的示例将数据从data.file索引到 弹性搜索位于http://myserver:9200/myindex/mytype:
python -m esimport -s myserver:9200 -f /path/to/import/data.file -i myindex -t mytype
- -sserver(可以是hostname:port,也可以是完全限定的,即。 https://servername:port)
- -ffilepath(要从中导入数据的制表符分隔文件的位置)
- -iindexname(elasticsearch中目标索引的名称)
- -ttypename(目标文档类型的名称 弹性搜索)
可通过脚本获得更多帮助:
python -m esimport --help
其他选项
自定义分隔符
操作的默认分隔符是“,”,但可以通过-d参数指定不同的分隔符。
python -m esimport -s myserver:9200 -f /path/to/import/data.file -i myindex -t mytype -d '|'
- -d分隔符(csv中分隔列的分隔符)
先清除现有数据< /H4>
在弹性搜索中索引数据时,您可以选择清除 通过包含-RM添加数据之前的现有弹性搜索类型 争论。
python -m esimport -s myserver:9200 -f /path/to/import/data.file -i myindex -t mytype -rm
- -rm(删除指定索引中给定类型的所有文档 关于弹性搜索)
映射
映射是对 在ElasticSearch中索引的文档。场等特性 类型、字段是否可搜索以及是否包含时间戳 都可以在地图上定义。
如果指定的映射与字段名不匹配,请注意:。 在制表符分隔的文件中,应该提供字段转换文件 (如下所述)。
可以通过将-m参数添加到 命令:
python -m esimport -s myserver:9200 -f /path/to/import/data.file -i myindex -t mytype -m /path/to/mapping.json
- -mmappingfilepath(json格式映射文件的位置 指定类型)
映射应该以json格式提供,如下所示 ElasticSearch网站。
文档类型“tracks”的样本映射
{"tracks":{"properties":{"genre":{"type":"string"},"album":{"type":"string"},"ISRC":{"type":"string"},"recordCompany":{"type":"string"},"artist":{"type":"string"},"songToken":{"type":"integer"},"durationInSeconds":{"type":"integer"},"title":{"type":"string"}}}}
有关映射的详细信息可以在ElasticSearch’s mapping reference中找到。
字段翻译
如果CSV文件中的原始字段名需要更改或 在导入过程中筛选,您可以提供字段翻译文件。 此文件的第一行应包含原始字段名, 由指定的分隔符分隔;第二个是新名称 用指定的分度计隔开。
请注意:第一行中省略的任何原始字段名,都将 也从索引数据中省略。这是一种方便的过滤方法 如果需要的话,索引时的列。
python -m esimport -s myserver:9200 -f /path/to/import/data.file -i myindex -t mytype -rm -m /path/to/mapping.json -n /path/to/field/name/translations.file
- -n字段翻译文件路径(csv字段的位置 指定类型的翻译文件)
示例字段名翻译文件
Album_Category,Album_ID,ISRC,Record_Co,Song_Artist,Song_ID,Song_Secs,Song_Title
genre,albumID,ISRC,recordCompany,artist,songID,duration,title
基本验证
如果需要登录凭据,请添加参数-user和-pass
python -m esimport -s https://myserver.com -f /path/to/import/data.file -i myindex -t mytype -user exampleuser -pass examplepassword
验证SSL
如果elasticsearch需要ssl,-nv设置可用于在必要时绕过证书验证。
python -m esimport -s https://myserver.com -f /path/to/import/data.file -i myindex -t mytype -user exampleuser -pass examplepassword -nv
批量索引计数
您可以使用-bc参数指定一次要索引的最大记录数(默认值为1000)。
python -m esimport -s https://myserver.com -f /path/to/import/data.file -i myindex -t mytype -user exampleuser -pass examplepassword -bc 500
超时
您可以使用-t参数指定与ElasticSearch通信的超时(默认为60)。
python -m esimport -s https://myserver.com -f /path/to/import/data.file -i myindex -t mytype -user exampleuser -pass examplepassword -T 30
依赖关系
- Python库
- rawes:Github| documentation
- 弹性搜索