我有一个elasticsearch索引,有60k个元素。我知道通过检查head
插件,我通过Sense得到相同的信息(结果在右下角)
然后,我想用两种不同的方式从Python查询相同的索引:通过直接的requests
调用和使用elasticsearch
模块:
import elasticsearch
import json
import requests
# the requests version
data = {"query": {"match_all": {}}}
r = requests.get('http://elk.example.com:9200/nessus_current/_search', data=json.dumps(data))
print(len(r.json()['hits']['hits']))
# the elasticsearch module version
es = elasticsearch.Elasticsearch(hosts='elk.example.com')
res = es.search(index="nessus_current", body={"query": {"match_all": {}}})
print(len(res['hits']['hits']))
在这两种情况下,结果都是10
-与预期的60k相差甚远,查询的结果是有意义的(内容是我所期望的),只是其中只有几个。在
我取了这10次中的一次,用Sense查询它的_id
来关闭循环。正如预期的那样,我们发现:
所以看起来这10个命中是整个索引的一个子集,为什么Python版本的调用中没有报告所有的元素?在
10 is the default size of the results returned by Elasticsearch。如果需要更多,请指定
"size": 100
。但是,请注意,不建议使用size返回所有文档,因为这样会导致集群崩溃。要返回所有结果,请使用scan&scroll。在我认为应该是}来获得总点击数。在
res['hits']['total']
而不是{相关问题 更多 >
编程相关推荐