Python ElasticSearch查询到数据帧
我有一个问题:Python ElasticSearch查询到数据帧,python,pandas,elasticsearch,Python,Pandas,elasticsearch,我有一个问题: 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行的数据帧转换此词典基于您的评论,我想您要查找的是大小: es.se
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行的数据帧转换此词典基于您的评论,我想您要查找的是大小:
es.search(index="my-index", doc_type="mydocs", body="your search", size="1000")
我不确定这是否适用于627033行-您可能需要滚动
如果您的请求可能从Elasticsearch返回10000多个文档,则需要使用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_u开头的字段,以对应您自己的值您能否提供有关ElasticSearch查询输出的更多信息?如果只是字典,那么问题应该是将字典转换为数据帧。关于这个问题有很多答案,例如,实际上我搜索的不是字典的格式,但它总是只返回我想要的10个元素