[英]Elasticsearch : retrieve all documents from index with python
我需要从Python中的Elasticsearch检索文档。
所以我写了这个小代码:
es = Elasticsearch(
myHost,
port=myPort,
scheme="http")
request = '''{"query": {"match_all": {}}}'''
results = es.search(index=myIndex, body=request)['hits']['hits']
print(len(results))
>> 10
问题在于,当我希望有几百个文档时,它仅从索引中返回10个文档。 如何从索引中检索所有文档?
您有几种方法可以解决此问题。
如果知道索引中将包含的最大文档数量,则可以将搜索的size
参数设置为该数量或更大。 例如,如果您知道少于100,则可以通过以下方式检索它们: results = es.search(index=myIndex, body=request, size=100)['hits']['hits']
如果您不知道该数字,但仍然想要所有这些数字,则必须使用scan
功能,而不是search
功能。 该文档在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.