【问题标题】:Get result sorted by "@timestamp" in python using elasticsearch-dsl使用elasticsearch-dsl在python中获取按“@timestamp”排序的结果
【发布时间】:2018-12-26 00:48:44
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    scroll 可以与sort 一起使用,您只需使用preserve_order 调用它:s.params(preserve_order=True).scan()

    希望这会有所帮助!

    【讨论】:

    • 当我使用上述设置时,它显示此错误:-“ScanError: Scroll request has failed on 30 shards out of 32”
    • 您遇到的错误是什么?捕获异常并打印其.info 属性
    • “错误:滚动请求在 41 个分片中的 38 个分片上失败”这是我遇到的错误。
    • 这只是消息,请捕获异常并打印出其.info 属性。这只是告诉你出了什么问题,而不是为什么,它没有帮助
    • 这是回溯:- 回溯(最近一次调用最后一次):文件“check_dsl.py”,第 41 行,在 run_query 中响应命中:文件“/usr/local/lib/python2. 7/dist-packages/elasticsearch_dsl/search.py​​”,第 701 行,在扫描 **self._params 文件“/usr/local/lib/python2.7/dist-packages/elasticsearch/helpers/__init__.py”,行316,在扫描中 (resp['_shards']['failed'], resp['_shards']['total']) ScanError: 44 个分片中的 41 个分片的滚动请求失败。
    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 2018-10-11
    • 2022-09-23
    • 2013-09-20
    • 1970-01-01
    相关资源
    最近更新 更多