我使用Elasticsearch作为我的后端。
在我的一个观点中,我做了一个像这样的过滤器:
SearchQuerySet().filter(...)
然后它返回55个对象。
然后,我在for循环中迭代结果,对每个对象执行一些操作。
结果如预期。但是,当我检查elasticsearch的日志时,我看到这样的事情:
[12:38:16,504] {"time":"2015-07-22T12:38:16.504+05:00","starttime":"2015-07-22T12:38:16.502+05:00","localaddr":"127.0.0.1","localport":9200,"remoteaddr":"127.0.0.1","remoteport":58718,"scheme":"http","method":"GET","path":"/haystack/modelresult/_search","querystr":"_source=true","code":200,"status":"OK","size":13633,"duration":2,"year":"2015","month":"07","day":"22","hour":"12","minute":"38","dow":"Wed","cluster":"elasticsearch_venta","data":"{\"query\": {\"filtered\": {\"filter\": {\"terms\": {\"django_ct\": [\"items.item\"]}}, \"query\": {\"match_all\": {}}}}, \"from\": 0, \"size\": 10}"}
[12:38:16,509] {"time":"2015-07-22T12:38:16.509+05:00","starttime":"2015-07-22T12:38:16.508+05:00","localaddr":"127.0.0.1","localport":9200,"remoteaddr":"127.0.0.1","remoteport":58718,"scheme":"http","method":"GET","path":"/haystack/modelresult/_search","querystr":"_source=true","code":200,"status":"OK","size":13719,"duration":1,"year":"2015","month":"07","day":"22","hour":"12","minute":"38","dow":"Wed","cluster":"elasticsearch_venta","data":"{\"query\": {\"filtered\": {\"filter\": {\"terms\": {\"django_ct\": [\"items.item\"]}}, \"query\": {\"match_all\": {}}}}, \"from\": 10, \"size\": 10}"}
[12:38:16,515] {"time":"2015-07-22T12:38:16.515+05:00","starttime":"2015-07-22T12:38:16.513+05:00","localaddr":"127.0.0.1","localport":9200,"remoteaddr":"127.0.0.1","remoteport":58718,"scheme":"http","method":"GET","path":"/haystack/modelresult/_search","querystr":"_source=true","code":200,"status":"OK","size":13429,"duration":2,"year":"2015","month":"07","day":"22","hour":"12","minute":"38","dow":"Wed","cluster":"elasticsearch_venta","data":"{\"query\": {\"filtered\": {\"filter\": {\"terms\": {\"django_ct\": [\"items.item\"]}}, \"query\": {\"match_all\": {}}}}, \"from\": 20, \"size\": 10}"}
也就是说,SearchQuerySet每次都会返回10个项目。
我尝试了load_all
,但没有帮助。
我认为这是因为SearchQuerySet返回了一个分页结果。
如何将对elasticsearch的请求数量减少为1,即一次性获取所有项目?
答案 0 :(得分:0)
在SearchView中将results_per_page
设置为无。 SearchView在官方回购中被定义为:
class SearchView(object):
...
results_per_page = RESULTS_PER_PAGE
答案 1 :(得分:0)
SearchQuerySet().filter(...).query.get_results()