I am trying to figure out how to include a lookup in my search, but only some records. My current search is below. My company has two issues:
I want the lookup to only include records where the "host_type" is "application", not "db". Here is my search:
`Environments(PRODUCTION)` sourcetype=appservice "updaterecords" AND "version"
| eval host = lower(host)
| lookup clientlist.csv hostname as host, OUTPUT clientcode as clientCode
| eval displayName = IF(client!="",client,clientCode)
| rex field=_raw "version: (?<AppVersion>.*)$"
| eval VMVersion = replace(AppVersion,"release/","")
| eval CaptureDate=strftime(_time,"%Y-%m-%d")
| dedup clientCode
| table displayName,AppVersion,CaptureDate
I did try including host_type right after "..hostname as host.." and using a |where clause later, but that did not work.
You can do conditional lookup using the eval form of lookup
| eval LookupResult=if(host_type="application", lookup("clientlist.csv", json_object("hostname", host), json_array("clientcode")), null())
You will get back a field called LookupResult like
{"clientcode":"abc"}
and you can then extract the value abc from the result.
You can do conditional lookup using the eval form of lookup
| eval LookupResult=if(host_type="application", lookup("clientlist.csv", json_object("hostname", host), json_array("clientcode")), null())
You will get back a field called LookupResult like
{"clientcode":"abc"}
and you can then extract the value abc from the result.