Splunk Dev

How to preview partial job results in JavaScript SDK?

omerl
Path Finder

Hey!
I'm trying to run a search in the JS Splunk SDK, and periodically check the job for the current results. I found out that there are multiple exec_modes possible, and if I set it to normal, I can get the job ID before the search has ended.
I tried to run my job this way:

service.search(
  searchQuery,
  searchParams,
  async function (err, job) {
    console.log("...done!\n");
    let count = 0;
    const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
    await sleep(4000);
    job.preview({}, function (err, results) {
      if (err) {
        console.error(err)
        return;
      }
      if (results.rows) {
        count++;
        console.log("========== Iteration " + count + " ==========");
        console.log(results.rows)
        for (var i = 0; i < results.rows.length; i++) {
          var row = results.rows[i];
          console.log(stat + row[countIndex]);
        }
        console.log("=================================");
      }
    });
});

with these properties:

const searchQuery = "search index=*";
const searchParams = {
  exec_mode: "normal"
};

The output of this job.preview is that there are no rows yet.

Is there anything wrong with the way I'm checking the job results? Is there a way to achieve the results before the job ends?

Thanks!

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 ...