gpt4 book ai didi

python - 如何使用python客户端获取所有在Elasticsearch索引下的文档?

转载 作者:行者123 更新时间:2023-12-03 00:34:50 25 4
gpt4 key购买 nike

我正在尝试使用python客户端获取所有索引文档,但结果仅显示第一个文档
这是我的python代码:

res = es.search(index="92c603b3-8173-4d7a-9aca-f8c115ff5a18", doc_type="doc", body = {
'size' : 10000,
'query': {
'match_all' : {}
}
})
print("%d documents found" % res['hits']['total'])
data = [doc for doc in res['hits']['hits']]
for doc in data:
print(doc)
return "%s %s %s" % (doc['_id'], doc['_source']['0'], doc['_source']['5'])

最佳答案

默认情况下,Elasticsearch仅检索10个文档。您可以更改此行为-doc here。分页的最佳实践是 search after query scroll query 。这取决于您的需求。请阅读此答案Elastic search not giving data with big number for page size

要显示所有结果:

for doc in res['hits']['hits']:
print doc['_id'], doc['_source']

关于python - 如何使用python客户端获取所有在Elasticsearch索引下的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50210299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com