[英]Python elasticsearch.helpers.scan example
Can someone provide scan API example of python elasticsearch helpers client? 有人可以提供python elasticsearch助手客户端的扫描API示例吗?
res = elasticsearch.helpers.scan(....)
How can i get all results from elasticsearch with res object? 如何从res对象获得elasticsearch的所有结果?
The documentation includes an example, although if I'm reading it right, helpers.scan
by default sets search_type=scan
, which was removed in ES 5.1 . 该文档包含一个示例,但如果我正确读取它,
helpers.scan
默认情况下helpers.scan
设置search_type=scan
,这已在ES 5.1中删除 。 This causes the example code to fail with ES returning No search type for [scan]
. 这会导致示例代码失败,ES返回
No search type for [scan]
。 We can amend this with preserve_order=True
(I am however not sure about the performance implications here): 我们可以使用
preserve_order=True
来修改它(但我不确定这里的性能含义):
import elasticsearch
import elasticsearch.helpers
es = elasticsearch.Elasticsearch()
results = elasticsearch.helpers.scan(es,
index="test_index",
doc_type="my_document",
preserve_order=True,
query={"query": {"match_all": {}}},
)
for item in results:
print(item['_id'], item['_source']['name'])
This helper returns an object which you can iterate to obtain the actual results from the query. 此帮助程序返回一个对象,您可以迭代该对象以从查询中获取实际结果。
item
is of form item
是形式的
{'_index': <str>, '_type': <str>, '_id': <str>, '_score': <float or None>, '_source': {'key': val}, 'sort': [<int>]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.