如何从ElasticSearch helpers.scan结果获取Python数据帧
假设我有一个助手函数,如:如何从ElasticSearch helpers.scan结果获取Python数据帧,python,
elasticsearch,dataframe,Python,
elasticsearch,Dataframe,假设我有一个助手函数,如: result_helper = helpers.scan(es, scroll='2m', query={"query": {"match_all": {}}} ,index="test", size=1000, _source=('logtime','host_name', 'kv', 'value') ) 如何将这些数据放入python数据框中 采用这种方法: result_helper = list(helpers.scan(es, scroll='2m',
result_helper = helpers.scan(es, scroll='2m', query={"query": {"match_all": {}}} ,index="test", size=1000, _source=('logtime','host_name', 'kv', 'value') )
如何将这些数据放入python数据框中
采用这种方法:
result_helper = list(helpers.scan(es, scroll='2m', query={"query": {"match_all": {}}} ,index="test", size=1000, _source=('logtime','host_name', 'kv', 'value') ))
df = pd.DataFrame(result_helper)
我得到一个数据帧,但在\u source
列中有一个列表:
_id _index _score _source _type sort
0 AVz3qBfbLK0jC-lSNFjT test None {u'host_name': u'hostxyz', u'kv': u'Memory_an... logs [0]
如何从helpers.scan结果中为\u source
列表中的每个键创建一个数据框?
例如:
经过一些考虑和测试,我开发了以下解决方案: 与 及 我以列的形式获取列表(根据需要):
经过一些考虑和测试,我开发了以下解决方案: 与 及 我以列的形式获取列表(根据需要):
hostname memory ...
1 hostxyz 1024GB ...
2 . .
3 . .
4 . .
result_helper_list = list(helpers.scan(es, scroll='2m', query={"query": {"match_all": {}}} ,index="check_mk_wnp_csh", size=1000, _source=('logtime','host_name', 'kv', 'value') ))
df_result = json_normalize(result_helper_list)
df_result.columns
> Index([u'_id', u'_index', u'_score', u'_source.host_name', u'_source.kv',
u'_source.logtime', u'_source.value', u'_type', u'sort'],
dtype='object')