Splunk Search

Using PHP SDK to filter fields

EricLloyd79
Builder

Hello I am currently using this code to return a search but its giving me all the fields and I only want certain ones. I was hoping I could pass parameters in somewhere and filter them but can't figure this out. Any help

$job = $service->getJobs()->create($search, array('rf' => '_time'));

$results = $job->getResults();

foreach ($results as $result)
{
    if ($result instanceof Splunk_ResultsFieldOrder)
    {
        // Process the field order
        printf ("FIELDS: " . implode(',', $result->getFieldNames()) . "\r\n");
Tags (4)
0 Karma

Damien_Dallimor
Ultra Champion

You can solve this by simply adjusting your Splunk Search to return only the fields you are interested in by using the "fields" command.

Examples :

index=foo sourcetype=goo | fields field1, field2
index=foo sourcetype=goo | fields - _* | fields + field1, field2

Let Splunk do the work for you.

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...