我有一个疑问:
s = Search(using=client, index='myindex', doc_type='mytype')
s.query = Q('bool', must=[Q('match', BusinessUnit=bunit),
Q('range', **dicdate)])
res = s.execute()
返回 627033 行,我想将此字典转换为包含 627033 行的数据帧
最佳答案
如果您的请求可能从Elasticsearch返回超过10,000个文档,您将需要使用Elasticsearch的滚动功能。该函数的文档和示例很难找到,因此我将为您提供一个完整的、有效的示例:
import pandas as pd
from elasticsearch import Elasticsearch
import elasticsearch.helpers
es = Elasticsearch('127.0.0.1',
http_auth=('my_username', 'my_password'),
port=9200)
body={"query": {"match_all": {}}}
results = elasticsearch.helpers.scan(es, query=body, index="my_index")
df = pd.DataFrame.from_dict([document['_source'] for document in results])
只需编辑以“my_”开头的字段即可对应您自己的值
关于python - ElasticSearch 查询 pandas 数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46471922/