V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
smartwusir007
V2EX  ›  Python

es 如何控制只保存限制天数的日志,哪种方法更好?

  •  
  •   smartwusir007 · 2019-11-24 12:34:32 +08:00 · 3697 次点击
    这是一个创建于 1587 天前的主题,其中的信息可能已经有所发展或是发生改变。
    网上查了有两种方法:
    1. 给每天的数据建立一个索引,如 index-systemlog-2019-11-24,然后定期删除索引就行
    2. 数据放到同一个索引中,然后利用 delete_by_query 写脚本定时删除过期脚本
    感觉第一种更合理一些,第一种的话查的时候也可以通过通配符来查询,不知道用过的大神你们是怎么控制的?
    9 条回复    2020-09-07 17:37:42 +08:00
    lihongjie0209
        1
    lihongjie0209  
       2019-11-24 13:00:55 +08:00
    怎么实现都可以, 取决于你们的业务需求和数据量吧。
    teenart
        2
    teenart  
       2019-11-24 13:31:14 +08:00 via Android
    1 方法比较好,2 方法数据量大以后性能有问题
    zibber
        3
    zibber  
       2019-11-24 16:21:37 +08:00
    量大是不是 1 比较好
    janxin
        4
    janxin  
       2019-11-24 16:26:33 +08:00
    用的 1 方法
    yty2012g
        5
    yty2012g  
       2019-11-24 16:32:17 +08:00
    一般是用 1 的方法,然后 ES 有索引生命周期管理,通过配置可以自动定期删除过期的索引。而且按天建索引,一天的数据在一个文件夹内,删除性能更好
    smartwusir007
        6
    smartwusir007  
    OP
       2019-11-24 17:16:03 +08:00
    thankx @all 看来数据量大的时候用方法 1 更清晰一些,但会建立更多的索引,对性能有影响吧,方法 2 的话数据量特别大的话查询删除部分数据比较慢把
    Morriaty
        7
    Morriaty  
       2019-11-24 21:50:43 +08:00
    es6.3 版本之前用 elasticsearch-curator,6.3 之后自带 ILM,索引生命周期管理
    smartwusir007
        8
    smartwusir007  
    OP
       2019-11-25 23:03:20 +08:00
    @Morriaty 受教了
    zhengdai1990
        9
    zhengdai1990  
       2020-09-07 17:37:42 +08:00
    想知道方案 1 的性能损耗大概多少
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5385 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:59 · PVG 14:59 · LAX 23:59 · JFK 02:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.