-1

I am working with kibana (elasticsearch dashboard) which allow to specify a date pattern to explain the index naming pattern.

For instance, default pattern is: [logstash-]YYYY-MM-DD.HH

I'd like to organize my index by block of hours, let's say by block of 4 hours. Indices would then be named logstash-2014-02-25.00, logstash-2014-02-25.04, logstash-2014-02-25.08, …</p>

Is there any way to get such format with momentjs ? I am dreaming of [logstash-]YYYY-MM-DD.{HH%4} but the documentation does not explain such thing (how weird).

4

1 回答 1

0

使用格式化原语似乎不可能做到这一点。

但是,我发现我们可以覆盖一些依赖于语言的格式化程序,例如 meridiem 格式化程序。然后一个解决方案是在某处插入(例如在 kibana conf 文件中):

moment.lang('fourHourblocks', {
  meridiem: function(hour, minute, isLowercase) {
    hourBlock = Math.floor(hour / 4).toString();
    if (hourBlock.length < 2) hourBlock = "0" + hourBlock;
    return hourBlock;
  }
}

然后我可以将模式设置为[logstash-]YYYY-MM-DD.A.

这有点老套,所以我仍然愿意接受其他解决方案

于 2014-02-25T15:40:55.803 回答