python - 提高 elasticsearch-py 扫描的速度

标签 python python-3.x elasticsearch elasticsearch-2.0 elasticsearch-py

我正在寻找一种方法来提高 Elasticsearch 数据的滚动扫描速度。
以下 python 代码扫描多个索引并将结果输出到控制台和位于某处的文件。
我的测试得出的结论是,这种方法效率极低,并且需要大量时间(10 个事件/秒?)。我猜这是由一些内部默认值或限制引起的。
有没有一种方法可以设计它以获得更好的性能?

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q

client = Elasticsearch(
    [
        'http://localhost:9201/',
    ],
    verify_certs=True
)

search = Search(using=client, index="test1,test2,test3") \
    .filter(Q("wildcard", name="bob*") & Q("term", color="green")) \
    .filter('range', **{'@timestamp':{'gte': 'now-2d', 'lt': 'now'}}) \
    .sort('@timestamp') \
    .params(preserve_order=True)



file = open("X:/files/people.txt", "a")
for hit in search.scan():
    line = (hit.message + "\n")
    file.write(line)
    print(line)

file.close()

感谢您对此进行调查:)

最佳答案

老问题,但可能对其他人有帮助:

另外两件事要尝试的是调整大小,找到适合您环境的最佳值。此外,如果您不需要完整的 _source,请尝试使用 _source_exclude_source_include 消除字段,我已经看到使用这些方法可以显着提高性能。

关于python - 提高 elasticsearch-py 扫描的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51266587/

相关文章:

elasticsearch - Kafka 连接到 ElasticSearch 是否可以进行更新

python - Django: python manage.py runserver 给出 RuntimeError: maximum recursion depth exceeded in cmp

python - 如何正确使用for循环从python中的csv绘制多行?

python - 导入函数时它运行整个脚本?

python - 创建空矩阵 Python

python-3.x - 在Docker容器中查找gunicorn日志文件

python-3.x - 在 python 脚本中运行 powershell 脚本

elasticsearch - Elasticsearch 和Logstash性能调优

python - XlsxWriter 将日期写入数字

amazon-web-services - 删除亚马逊 Elasticsearch 中的旧索引