我正在尝试使用弹性搜索库pyelasticsearch
,elasticsearch
但我没有得到任何可以传递数据框的方法,并且该方法会将数据框数据加载到弹性搜索中。
我正在尝试这个代码:
for i,df in enumerate(csvfile):
print (i)
records=df.where(pd.notnull(df), None).T.to_dict()
list_records=[records[it] for it in records]
print(list_records)
try :
es.bulk_index("call_demo_data1","tweet",list_records)
except :
print ("error!, skiping some tweets sorry")
pass
其中 csvfile 是我的所有数据都存在的数据框。但我收到以下错误
'str' object has no attribute 'where'
我在评论中使用了推荐
现在这个问题已经解决了,我在批量加载时遇到了这个错误
我正在使用上述方法加载数据弹性搜索我遇到了问题所以这里是我之前发布的问题的链接
这是我现在使用的代码:
records= csvfile.T.to_dict()
list_records=[records[it] for it in records]
#print(list_records)
es.bulk_index("call_demo_data1","tweet",list_records)
我得到的错误是:
too many values to unpack (expected 2)
批量索引时出现此错误。上面代码中的 csvfile 是一个数据框。我正在使用这个图书馆pyelasticsearch