説明
指定した1つ以上のフィールドに基づいて、検索結果行を同じ結果セット内の他の検索結果行と結合します。
記述方法
selfjoin [<selfjoin-options>...] <field-list>
引数
<field-list>
結合したいフィールド
オプション引数
overwrite=<bool>とmax=<int>
join参照
keepsingle=<bool>
base.spl
| makeresults
| eval _raw="id name owner_id
1 aka 1
2 ao 2
3 shiro 1
4 kuro 4"
| multikv forceheader=1
| table id name owner_id
| append
[|makeresults
| eval _raw="id name
1 ichiro
2 jiro
3 saburo"
| multikv forceheader=1
| table id name]
id | name | owner_id |
---|---|---|
1 | aka | 1 |
2 | ao | 2 |
3 | shiro | 1 |
4 | kuro | 4 |
1 | ichiro | |
2 | jiro | |
3 | saburo |
keepsingle=true
keepsingle_t.spl
....
| selfjoin keepsingle=t id
id | name | owner_id |
---|---|---|
1 | aka | 1 |
2 | ao | 2 |
3 | shiro | 1 |
4 | kuro | 4 |
keepsingle=false
keepsingle_f.spl
....
| selfjoin keepsingle=f id
id | name | owner_id |
---|---|---|
1 | aka | 1 |
2 | ao | 2 |
3 | shiro | 1 |
デフォルトはfalse
使用方法
1時間ごとの集計の間に各5分間の数値をあいだに入れた表。
selfjoin.spl
index=_internal sourcetype=splunkd
| bin span=10m _time
| eval timeA= _time
| bin span=1h _time
| eval timeB= _time
| multireport [ chart count as count5m by source timeA]
[ chart count as count1h by source timeB]
| foreach 15* [ eval time_<<FIELD>>=strftime("<<FIELD>>","%T")
| eval {time_<<FIELD>>} = '<<FIELD>>'
| fields - <<FIELD>> time_<<FIELD>>]
| selfjoin source
append
とかappedpipe
でつくった行をさっとくっつけるのに使用するselfjoin
2行しかくっつけられないのでそれだけ注意すると、こんなこともできます。
multireport
はSplunk>docsに載っていないけど、動作としてはこんな感じで二つの集計を走らせることができます。
まとめ
表を軽く、くっつけることができるselfjoin
appendpipe
やappend
で2つの行をつくった時、くっつけるならこのコマンドを思い出してやってください。