python - 干草堆:stats()和stats_results()不起作用

标签 python django python-3.x elasticsearch django-haystack

Haystack和Django存在以下问题。我正在尝试做的是过滤模型Book的一些对象并获得最大和最小价格。基本上,下面是查询,其中sq是动态生成的查询:

partial_query = SearchQuerySet().models(Books).filter(sq)

此返回大约10个结果。
在检查了Haystack(http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html)的文档后,发现stats('price'),stats_results()对我来说很好用,但是由于某种原因,我看到的唯一输出是None。下面是代码:
partial_query = SearchQuerySet().models(Listing).filter(sq).stats('price')
partial_query.stats_results()

经过几次测试,我发现实际上以下打印品可以达到他们期望的效果。
print(partial_query[0].price) #for example 123
print(partial_query) #list with about 10 objects

另外,如果您知道通过此查询获取最高和最低价格的任何其他方法,请随时与我分享:)。我将不胜感激。谢谢。

最佳答案

从标签上听起来好像您正在使用Elasticsearch,但按照haystack documentation

This is supported on Solr only.

关于python - 干草堆:stats()和stats_results()不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221032/

相关文章:

python - 将 12 小时格式转换为 24 小时 Python

python - 在我自己的 View 中使用 django PasswordResetView 功能

django - 我如何从 Tastypie JSON 访问 Backbone 集合元素?

python - 身份验证失败 : [Errno 1] _ssl. c:510: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

python - 在 Python 2.7 中打印重音字符

python - get_highest_resolution 函数在 pytube 中不起作用

python-3.x - 使用 boto3 和 python3,我无法对 ClientContext 的 JSON 进行 Base64 编码?

python - Python 3 中的嵌套 map

linux - 使用 nodebox 作为 python 3.5 的模块

python - Pandas groupby 分别制作两列列表