我正在寻找一种方法来提高 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/