where
whereコマンドを使用して、trueまたはfalseとなる式の値を計算します。
構文
*|where <expression>コマンドで使用可能な演算子
次の表に、whereコマンドで使用できる演算子を示します。比較におけるユーザーフレンドリな時間文字列も参照してください。
| カテゴリ | 例 |
|---|---|
|
算術演算子 |
+, -, *, /, % |
|
比較演算子 |
=, !=, <, >, <=, >= |
|
論理演算子 |
and, or, not |
|
条件演算子 |
if(<expression>,<expression>,<expression>) |
|
複数比較演算子 |
in, not in |
コマンドで使用可能な関数
次の表に、whereコマンドで使用できるファンクションを示します。
| カテゴリ | 例 |
|---|---|
|
文字列ファンクション |
|
|
数値ファンクション |
|
|
日付ファンクション |
|
|
条件ファンクション |
|
|
ハッシュ・ファンクション |
|
|
三角関数 |
|
パラメータ
次の表に、このコマンドで使用されるパラメータとその説明を示します。
| パラメータ | 説明 |
|---|---|
|
|
trueまたはfalseの値を計算する必要がある式を指定します。 |
比較でのユーザーフレンドリな時間文字列
新機能により、人間が読める文字列を使用して問合せの時間を操作できます。これまでは、toDuration()を使用して、非常に特定の形式で期間を提供する必要がありました。
例1: タイムスタンプ・フィールドに期間を追加します。
*
| eval '10mins. after End Time' = 'Event End Time' + 10mins
| fields 'Event End Time', '10mins. after End Time'
例2: 2時間以上かかったジョブを検索します。
* | where 'Event End Time' - Time > 2hrs
例3: 1日以上か数ミリ秒未満のアイテムを検索します。
*
| link
| where Count > 1000 and
('End Time' - 'Start Time' > 3hour or 'End Time' - 'Start Time' < 2ms)
時間文字列は、timestatsのspanパラメータで使用される値です。timestatsのtimescaleの値のリストを参照してください。
一般的なシナリオでwhereコマンドを使用する例は、次を参照してください:
次に、whereコマンドの例を示します。
*|where severity = FATAL*|where 'Client Host City' = 'redwood city'*|where upper(severity) = FATAL*|where length(URI) >= 40*|where replace('aabbcc', 'bb', 'xx') = aaxxcc
*| where capitalize(severity) = Fatal*|where concat(host, concat(':', port)) != hostname
*|where contains(uri, '.com')*|where endsWith(uri, '.com')*|where startsWith(uri, 'http://oracle')
*|where decode64(value) = decodeValue
*|where encode64(uri) = encodeValue
*|where lastindexOf(uri, '.com') != -1
*|where reverse(Command) = smaraptini*|where host || ':' || port != hostname*|where substr('aabbcc', 2, 4) = bb*|where round('Content Size') = 1000*|where floor('Content Size') > 1000*|where max('Content Size In', ''Content Size Out') < 1000*|where urlDecode('http%3A%2F%2Fexample.com%3A893%2Fsolr%2FCORE_0_0%2Fquery') = URI
*|where urlEncode(uri) = field*|where 'User Name' in (host1, host2)*| where arccos(angle) != NaN*| where arcsin(angle) != NaN*| where arctan(angle) != NaN*| where atan2(x, y) != null*| where cos(angle) > 0*| where sin(angle) > e()*| where sin(angle) > pi()*| where sin(angle) > 0*| where tan(angle) > 0*| where toDegrees(angle) > 45* | where toRadians(angle) > 0
次の例は、if条件ファンクションの使用方法を示します:
*|where if(Status = '200', OK, ERROR) = ERROR次の例は、フィールドsrvrhostipのIPアドレスをサブネット範囲と比較します。
*|where cidrmatch(srvrhostip, '192.0.2.254/25')次の例は、フィールドDelayの文字列値を返します。
*|where Status = literal(Delay)次の例は、両端から一致する文字を削除します。
*|where trim(Command,"\") = initparams次の例は、左端から一致する文字を削除します。
*|where ltrim('Error ID',0) = 76890次の例は、右端から一致する文字を削除します。
*|where rtrim('OS Process ID',2) = 3123次の例は、文字列Start Timeを、MM/dd/yyという日付書式の1/1/18と比較します。
*|where 'Start Time' > toDate('1/1/18', 'MM/dd/yy')次の例は、End TimeとStart Timeの値の差異を計算し、その文字列を0:0:45の期間と比較します。
*|where 'End Time' - 'Start Time' > toDuration('0:0:45') 次の例は、期間のフォーマットを0:0:45.000として指定します。
*|where formatDuration('End Time' - 'Start Time') = '0:0:45.000'次の例は、日付ファンクションの使用方法を示しています。
*|where 'Start Time' > dateAdd(now(), hour, -1)
*|where 'Start Time' > dateSet(now(), hour, 0, minute, 0, sec, 0, msec, 0)
*|where formatDate('Start Time', 'MM/dd/yyyy') = '01/15/2018'
*|where 'Start Time' - now() > 45000次の例は、uri文字列内の.comの位置を計算し、それが-1と等しくないかどうかを評価します。
*| where indexOf(uri, '.com') != -1whereコマンドでmd5、sha1、sha256およびsha512ハッシュ・ファンクションを使用して、ログ・データをフィルタできます。次の例は、フィールドuserの値がmd5("jack")であるかどうかを評価します。
*|where user = md5("jack")
次のコマンドは、エンティティ・フィールドのコンテンツを2つの部分に分割します。たとえば、パターンを持つエンティティ値host-phx-1.oraclevcn.comは、ドメイン値oraclevcn.comを持つHostおよびDomainという2つの仮想フィールドに分割されます。
* | extract field = Entity '(?P<Host>\w+)\.?(?P<Domain>.*)'
| where contains(Domain, 'oraclevcn.com')
| timestats count as logrecords by 'Log Source'次のコマンドは、入力値が数値の場合に、度で指定された2組のラットロング座標間の距離(マイル)を計算し、その距離が1000より大きいかどうかをチェックします。
* | where distance(lat1, long1, lat2, long2) > 1000 次のコマンドは、入力値が2つの文字列である場合に、2組のラットロング座標(度)の間の距離(マイル)を計算し、その距離が1000より大きいかどうかをチェックします。
* | where distance('lat1,long1', 'lat2,long2') > 1000