LoginSignup
0
0

More than 1 year has passed since last update.

ElasticsearchにTimestampから時間と曜日のフィールドを追記する方法

Last updated at Posted at 2022-09-03

kibanaで可視化する際に特定の曜日と時間を抽出して最大値を取得したかったのでメモ

indexにドキュメントを追加

POST inedx-00000/_doc
{
  "timestamp":"2022-09-02T09:01:02+0900"
}

indexにドキュメントを追加

POST inedx-00000/_update_by_query
{
  "script": {
    "lang": "painless",
    "source": """
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssx", Locale.JAPAN);
      String datetime = ctx['_source']['timestamp']; 
      OffsetDateTime offsetDateTime = OffsetDateTime.parse(ctx['_source']['timestamp'],formatter);
      ctx['_source']['hour'] = offsetDateTime.getHour();
      ctx['_source']['week'] = offsetDateTime.getDayOfWeek();
    """
  }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0