most_recent と least_recent
most_recent および least_recent operator は、withtime operator とともに使用する集計 operator であり、グループ内の最近または最も古い値を選択できます。
withtime operator にはフィールドを指定して、フィールドの値とタイムスタンプ (ミリ秒) を含む JSON オブジェクトを作成します。x_withtime 形式でフィールドを作成すると、検索結果の一部として表示されます。その後に most_recent および least_recent operator を使用して、x_withtime フィールドを参照し、データを並び替えます。
withtime、most_recent、および least_recent operator はスタンドアロン operator とは見なされません。これらは、first および last operator がサポートされていないライブ ダッシュボードや継続的なクエリで、その代替として使用するためにのみ設計されたものです。
構文
status
フィールドは次の構文式で使用して、任意のフィールドを表します。
| parse ... as status |
withtime
status | most_recent(status_withtime) by _sourcehost
| parse ... as status |
withtime
status | least_recent(status_withtime) by _sourcehost
例
サイトの最近のビジターを IP ごとに検索します。
サイトにヒットするビジターを国別にモニタリングするとします。次のクエリはログ行のメッセージ時刻に基づいて、最新の IP アドレスを表示します。
*ip* OR *address*
| parse regex "(?<IP>\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| lookup latitude, longitude, country_code from geo://location on ip=IP
| where !isNull(country_code)
| withtime IP
| most_recent(ip_withtime) by country_code
結果は次のようになります。