Splunk Search

Javascript: How to cancel a search mid run?

bmacias84
Champion

Hello,

I am trying to write a simple SPA using JS on the Search Head. I have a page where objects are generated dynamically based on a saved search. When an user clicks on an object, all other objects are hidden and the objects in focus pass data-device attribute to a second search which renders a new panel with data. This is fine except for when the user decides to switch focus mid search and they receive an error.


var poolSearch = new SearchManager({
    id: elementSearch,
    autostart: "true",
    latest_time: "now",
    earliest_time: "-1d@d",
    cache: 'false',
    search: splunkQuery
});
\
poolSearch.on('search:done', function(properties) {
                        console.log("DONE!\nSearch job properties:", properties.content);
                        var psearch = splunkjs.mvc.Components.getInstance(elementSearch);
                        var poolResults = psearch.data("results");
                        poolResults.on("data", function() {
                            console.log(poolResults.data());
                        });
                    });

I know how to check when a search is done or a search event has occurred, but how to cancel this search mid run?

Cheers,

0 Karma
1 Solution

bmacias84
Champion

Never mind on this I found the method. I was glazing over it.


poolSearch.cancel();

View solution in original post

bmacias84
Champion

Never mind on this I found the method. I was glazing over it.


poolSearch.cancel();

z3372129
New Member

Hi champ,

 

thanks for the post, just wondering if you could reference a search that's not created and run in JS and stop it amid searching? I.e. you have a search in xml, how do you reference it using Search Manager in JS.

 

many thanks again,

Derek

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