python-2.7 - 使用elasticsearch-dsl获取在python中按 “@timestamp”排序的结果

标签 python-2.7 elasticsearch elasticsearch-dsl elasticsearch-dsl-py

我想从我的代码的elasticsearch节点获取数据,我正在使用elasticsearch-dsl库从elasticsearch查询数据。现在,我希望根据“@timestamp”对数据进行排序,可以使用 sort api 来完成。但是我返回的数据具有超过10000个文档。我无法使用带有sort的scan来获取大数据,因为与一起使用sort不适用于elasticsearch-dsl中的scan 。有没有一种方法可以在elasticsearch-dsl中使用滚动api或任何其他方法来获取超过 10000个文档,并用“@timestamp” 排序。

最佳答案

scroll可以和sort一起使用,您只需要使用preserve_order来调用它即可:s.params(preserve_order=True).scan()
希望这可以帮助!

关于python-2.7 - 使用elasticsearch-dsl获取在python中按 “@timestamp”排序的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51396258/

相关文章:

python - 在异常上下文中获取函数的堆栈帧

java - Elasticsearch 1.2.1 异常 : Root type mapping not empty after parsing

Python PyES 和要插入的索引

Elasticsearch 嵌套基数聚合

elasticsearch - Elasticsearch 查询可以有空值参数吗?

python-3.x - 无法解析 ID 为 'DEMO_54ddab6' 的文档中类型为 [date] 的字段 [review_start_datetime]

elasticsearch - 字数统计或从doc_count获取文档

python-2.7 - OpenCV 3.2 名称错误 : global name 'FLANN_INDEX_LSH' is not defined

python-2.7 - 使用 Python API 在优化失败后获取 NLOpt 结果

Python 安装 xmlrpclib