python - 将python数据导出到elasticsearch
问题描述
我有以下数据框:
date_facture product_description ... nouv2 ecartt
0 2020/04/01 00:01:14 xyz ... 1.00 0.00
1 2020/04/01 00:02:29 None ... 2.00 1.00
2 2020/04/01 00:03:14 eu ... 1.00 0.00
3 2020/04/01 00:04:17 com ... 1.00 0.00
我想将它导出到 elasticsearch,为此我需要将其转换为适当的格式。
目前我的代码是:
es_url_rw = url_elastic
es_index_rw = 't_angelique'
def json_converter(o):
if isinstance(o, datetime.datetime):
return o.strftime("%Y/%m/%d %H:%M:%S")
print(requests.put(es_url_rw + es_index_rw).text)
headers = {'Content-type': 'application/json'}.
data = df.to_json()
bulk_json = []
bulk_json.append(json.dumps({'index': {'_index': es_index_rw, '_id': 123}}})))
bulk_json.append(json.dumps(data, default=json_converter))
requests.put(es_url_rw + '_bulk', data='\n'.join(bulk_json) + '\n', headers=headers)
但是这样做我找不到弹性数据。我知道问题出在这一行:
data = df.to_json()
确实,我第一次测试
data=df.to.dict()
使用所有可能的方向参数,我找到了弹性数据,但它们的格式不正确。当我测试时:
data=df.to_json()
我什至没有找到有关弹性的数据。我真的不知道现在该怎么办。请问你能帮帮我吗 ?
解决方案
推荐阅读
- html - 正则表达式匹配和移动 HTML
- python - 我正在尝试写一个“如果那么”声明。如果 df['time'] 格式为 YYYY,则 df['time']=df['year']。否则 df['time']=df['date2']
- oracle - Oracle IF 存在 THEN, ELSE
- c# - 如何在门户 C# 应用程序功能中访问 Azure 功能中的应用程序设置?
- r - 仅删除带有 NA 和/或零的列
- c++ - 如何包装具有参数的 C++ 类方法或在 C 中返回另一个 C++ 类的实例?
- html - vue 模板中的 eslint [vue/no-unused-vars] 错误
- windows - 大量空间,但 - [53100] 错误:无法写入块……:设备上没有剩余空间
- java - 为什么使用 Epsilon 与 G1 相比,观察到重复的内存分配更慢?
- gdb - 为什么使用浮点控制时 GDB 回溯受限?