# @splunk/search-job

> Create and access Splunk Enterprise search jobs

Latest version **3.1.1** (published 2026-11-05) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @splunk/search-job
pnpm add @splunk/search-job
yarn add @splunk/search-job
bun add @splunk/search-job
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2026-11-05 |
| First published | 2019-10-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 3 |
| Unpacked size | 64.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Splunk Inc. |
| Maintainers | splunker, vtsvetkov-splunk, splunk_sui_publish |

## Links

- npm: https://www.npmjs.com/package/@splunk/search-job
- Homepage: https://splunkui.splunk.com/Packages/search-job
- npm.io page: https://npm.io/package/@splunk/search-job

## Dependencies (3)

- [rxjs](https://npm.io/package/rxjs.md) ^5.4.2
- [lodash](https://npm.io/package/lodash.md) ^4.18.1
- [@splunk/splunk-utils](https://npm.io/package/@splunk/splunk-utils.md) ^4.2.0

## Recent versions

- 3.1.1 (latest) — 2026-11-05
- 3.1.0 — 2024-05-29
- 3.0.0 — 2024-01-16
- 2.0.1 — 2022-12-06
- 2.0.0 — 2021-02-05
- 1.1.1 — 2019-10-14

## README

# @splunk/search-job

A class that simplifies creating and accessing Splunk search jobs.

## Install

Install the package:
```
npm install @splunk/search-job
```

## Usage
```js
import SearchJob from '@splunk/search-job';
```

The API of the SearchJob class is based on [Observables](http://reactivex.io/rxjs/manual/overview.html#introduction). Each method returns an Observable that can be subscribed to and will emit data over the lifecycle of the search job. A few examples are provided here.

### Create a Simple SearchJob
```js
const mySearchJob = SearchJob.create({
    search: 'index=_internal | head 10',
    earliest_time: '-60m@m',
    latest_time: 'now',
});
```

### Create a SearchJob in a Specific Context
```js
const mySearchJob = SearchJob.create({
    search: 'index=_internal | head 10',
    earliest_time: '-60m@m',
    latest_time: 'now',
}, {
    app: 'awesome_app',
    owner: 'admin',
});
```

### Create a SearchJob from a Saved Search
```js
const mySearchJob = SearchJob.fromSavedSearch({
    name: 'My Saved Search',
    app: 'search',
    owner: 'admin',
});
```

### Get Search Progress
```js
const progressSubscription = mySearchJob.getProgress().subscribe(searchState => {
    // Do something with the searchState.
});

// Later, if the search is no longer needed, and is not complete,
// unsubscribe to release resources.
progressSubscription.unsubscribe();
```

### Get Search Results
Search results will only emit when the search is complete. See `getResultsPreview` to get a preview of results before the search is complete.
```js
const resultsSubscription = mySearchJob.getResults().subscribe(results => {
    // Do something with the results.
});

// Later, if the results are no longer needed, and the search is not complete,
// unsubscribe to release resources.
resultsSubscription.unsubscribe();
```

### Errors and Completion
All Observables support three callbacks: `next`, `error`, and `complete`.
```js
const progressSubscription = mySearchJob.getProgress().subscribe({
    next: searchState => {
        // Do something with the search state.
    },
    error: err => {
        // The search failed. Do something with the err.
    },
    complete: () => {
        // The search has completed successfully.
    },
});
```

---
_Source: https://npm.io/package/@splunk/search-job · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
