Splunk Search

search using join command

appleman
Contributor

Hello,

I want to combine two different searches and each different field by using join command.
However, I always get "No Results" whatever I tried.
Please give me some advice.

Thank you.


joinコマンドを利用して二つのサーチを繋げ、それぞれにある違うフィールドを掛け合わせたいのですが、上手くいきません。
それぞれのデータ量が重いため、collect indexでインデックスを作成しながらやっても駄目でした。
joinコマンドの正しい使い方をご教授下さい。

index=A sourcetype=logs source!=XXX.csv id=1234 name=* | stats count by id number | join [search index=tarot | table number name main_type2] | stats count by id name main_type2 number | sort - count | head 20

common field => number

Tags (3)
0 Karma
1 Solution

melonman
Motivator

if you are trying to have a reference from other source, try lookup.
create temporary lookup file by

... yoursearch | table fielda fieldb fieldc | outputlookup your_lookup.csv

then, do a search with the lookup command to lookup fields you need to put together.
* if your lookup file gets very big, then you can use lookup in DB using DB Connect.

View solution in original post

melonman
Motivator

if you are trying to have a reference from other source, try lookup.
create temporary lookup file by

... yoursearch | table fielda fieldb fieldc | outputlookup your_lookup.csv

then, do a search with the lookup command to lookup fields you need to put together.
* if your lookup file gets very big, then you can use lookup in DB using DB Connect.

appleman
Contributor

So basically, I need to put the data in DB which I can connect with DB connect.... Thank you very much!

0 Karma

melonman
Motivator

Well, there is no dblookup command. And for lookup data in DB by DB connect app, then you have to have the data in DB. If you can not connect your original DB where you exported the data from, then use the exported CSV as lookup (file based), or put the exported data into other database which is accessible by your splunk and configure DB connect to do lookup in database.

0 Karma

appleman
Contributor

Speaking of lookup, can I use dblookup even though the data is not in the DB? I mean, the data is exported from other DB which I can't put it in DB connect.

0 Karma

HiroshiSatoh
Champion

こんにちは。サーチ文だけからみると以下のような動きですがこれは求めている動きですか?

メインサーチ:id(1234)、number、count
サブサーチ: number、name、main_type2
をnumberでJOINすると結果はnumberが一致するデータのみ(デフォルト)になります。
id(1234固定)、(一致した)number、count、(サブサーチの)name、(サブサーチの)main_type2

これをstats count by id name main_type2 number しているので
id(1234固定)、(サブサーチの)name、(サブサーチの)main_type2、(一致した)number
となり、結果はサブサーチの値のみで、メインサーチはサブサーチのデータからnumberが一致しないデータを除外するために使われているだけになります。

HiroshiSatoh
Champion

テストしてませんが、statsを使った例です。

(index=A sourcetype=logs source!=XXX.csv id=1234) OR (index=tarot)
|stats dc(index) as idx_cnt,first(sub_name) as name,first(main_type2) as main_type2 by id,number
|where idx_cnt=2
|stats count by id,name,main_type2,number | sort - count | head 20

0 Karma

HiroshiSatoh
Champion

サブサーチの結果にidが存在しないので、idはメインサーチで指定されたidでかつサブサーチとnumberが一致するものとなります。メインサーチの| stats count by id number の部分でメインサーチ側のnameはなくなっているので気をつけて下さい。

また、サブサーチを使うことでパフォーマンスがでないようなら、メインサーチで両方抽出してstatsでひとつにまとめるようなこともできると思います。

0 Karma

appleman
Contributor

サブサーチの値で上書きされる旨、認識しておらず勉強になりました。ありがとうございます。ただこちらの事情により、実際のサーチとはフィールド名を変えてAnswersに掲載させて頂いているのですが、実際のサーチでは、nameのフィールドはそれぞれ別々のフィールド名が与えてあります。
idは値を指定しているので、固定になりますでしょうか。

0 Karma

HiroshiSatoh
Champion

JOINの場合同じフィールド名はサブサーチの値で上書きです。どちらかをリネームする必要があります。このサーチは | stats count by id number の部分でメインサーチ側のnameはなくなってます。

0 Karma

appleman
Contributor

メインとサブサーチのnameは違うフィールドになります。従って結果として求めているものは、(メイン)nameに対するid、(サブ)name、main_type2、(一致した)numberになります。

0 Karma

adityapavan18
Contributor

Hi appleman

I guess you need to mention the common field when using join something like this:

index=A sourcetype=logs
source!=XXX.csv id=1234 name=* | stats
count by id number | join number
[search index=tarot | table number
name main_type2] | stats count by id
name main_type2 number | sort - count
| head 20

joebensimo
Path Finder

Do the main and subsearch both return the expected results when run separately?

0 Karma

appleman
Contributor

I've tried this, but it turned out to be no result.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...