Splunk Search

How to get field values from search result using python script

ronak
Path Finder

My test script

splunk.auth.getSessionKey('admin','admin')
my_job = splunk.search.dispatch('search index=* source = orders.csv')
i = 0
for result in my_job.results:
result0 = my_job.results[i]
print i
i=i+1
print result0.fields

print result0['payment_type']

print result0.time

print result0.payment_type

Pl see attached two files - one has output of the print result0.fields and other is output of how the events look on search screen of Splunk (to indicate that there are many custom fields like payment_type, service_type etc alt text

Need

How do I print the content of the field payment_type or service_type ...I don't see them coming in when I print result0.fields.

Tags (4)
0 Karma

Flynt
Splunk Employee
Splunk Employee

Try adding |table * at the end of your search, this should allow any custom extracted fields to be displayed in your field output.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...