连接到ES并使用两种模式编写文档:追加和覆盖!
elasticwriter的Python项目详细描述
用于插入/更新ES文档
要构建并上传到pypi,运行两个命令
python setup.py b列表轮子
python-m捆绳上传距离/
如何使用
创建ES连接
import elasticwriter
from elasticwriter.elasticwriter import *
es = get_es([
"http://username:password@es-host"
])
如果不存在映射和设置,则创建索引
mapping = {
"_doc": {
"properties": {
"name": {
"type": "text",
},
}
}
}
index_name = 'tuan-test'
create_index_if_not_existed(es, index_name, mapping)
处理数据帧
test_df = spark.createDataFrame([(1, 'tuan', 30), (2, 'tank', 27)], ['es_id', 'name', 'age'])
push_df_to_index(es, index_name, test_df, 'overwrite')
处理列表字典
test_list = [
{'es_id': 3, 'name': 'tuyet', 'age': 25}
]
push_list_dict_to_index(es, index_name, test_list, 'overwrite')
import elasticwriter
from elasticwriter.elasticwriter import *
es = get_es([
"http://username:password@es-host"
])
mapping = {
"_doc": {
"properties": {
"name": {
"type": "text",
},
}
}
}
index_name = 'tuan-test'
create_index_if_not_existed(es, index_name, mapping)
test_df = spark.createDataFrame([(1, 'tuan', 30), (2, 'tank', 27)], ['es_id', 'name', 'age'])
push_df_to_index(es, index_name, test_df, 'overwrite')
处理列表字典
test_list = [
{'es_id': 3, 'name': 'tuyet', 'age': 25}
]
push_list_dict_to_index(es, index_name, test_list, 'overwrite')
test_list = [
{'es_id': 3, 'name': 'tuyet', 'age': 25}
]
push_list_dict_to_index(es, index_name, test_list, 'overwrite')