在elasticsearch中存储不同类别日志数据的最佳实践是什么

Which is the best practice to store different category log data in elasticsearch

参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

我们正在为多租户应用程序(例如:大约 10000 个租户)引入使用 elasticsearch 的日志。 我们需要记录 profile_edits、user_comments、cron_activities、category_edits 以及大约 30 个要记录的类别。

我找到了两种存储这些日志的方法。

  1. 每个租户一个索引
    POST tenant-1/_doc 
    {
       "type" : "profile_edits",
       "fullname" : "NewName",
       "age" : 11,
       "score" : 999
       ...
    }
    
    POST tenant-1/_doc 
    {
       "type" : "user_comments",
       "user" : "User1",
       "comment" : "Nice!"
    }

这样我就可以没有索引 = 没有租户。

  1. 租户共享索引
    POST profile_edits/_doc
    {
       "tenant" : 1,
       "fullname" : "NewName",
       "age" : 11,
       "score" : 999
    }

    POST user_comments/_doc 
    {
       "tenant" : 1,
       "user" : "User1",
       "comment" : "Nice!"
    }

这样我总共需要大约 35 个索引。

哪种方法效果更好?

它固执己见,但根据数据,我建议采用第二种方法,因为您的日志具有非常不同的结构,并且您最终会得到很多稀疏字段。

如果事情变大,您可以为专用租户使用索引或引入 daily/weekly/monthly/annual 索引。

同意另一位用户@Evaldas 的看法,这是基于意见的,但在我看来,以及相当多的大规模 ES 部署经验,我也觉得有基于您的类别的索引,例如 profile_editsuser_edits 并且有一个公共字段可能是 tenant_id,这对于过滤特定 tenant 的数据很有用。这种方法的优点很少。

  1. 您的索引管理开销相对较少,因为您只需要管理 35 个索引而不是 10k。

  2. 您仍然可以获得更好的性能,因为您可以在 tenant_id 上使用过滤器,并且文件管理器默认缓存在 ES 中,请参阅 filter context 了解更多信息。

  3. 集群状态(关于所有分片和状态的信息)会小得多,虽然在较新版本的 ES 中优化了集群状态的发布,但如果你使用的是真正的旧版本有帮助并提供更好的性能。

  4. 最后但并非最不重要的一点是,您的用例与本 official ES blog 中讨论的内容类似,他们还建议避免使用太多索引,而是建议将它们分组,如下所示是来自同一个博客的提示

TIP: In order to reduce the number of indices and avoid large and sprawling mappings, consider storing data with similar structure in the same index rather than splitting into separate indices based on where the data comes from. It is important to find a good balance between the number of indices and shards, and the mapping size for each individual index. Because the cluster state is loaded into the heap on every node (including the masters), and the amount of heap is directly proportional to the number of indices, fields per index and shards, it is important to also monitor the heap usage on master nodes and make sure they are sized appropriately.