Search progress events

After you've created a search manager, you can listen in on the events from the search (start, progress, done, cancelled, error, and failed) and handle them however you want. The search events return a properties object that contains the following fields: acl, author, content, id, links, name, published, and updated. The most interesting field is content, which is an object that contains all of the properties that are returned from the search job (such as eventCount and resultCount). For a complete list of these search job properties, see the Returned Values for the search/jobs endpoint in the REST API.

    Note  The search:done event is never fired for real-time searches because they never finish.

This JavaScript example runs a search and prints progress events to the console along with search job properties:

    require([
        "splunkjs/mvc/searchmanager",
        "splunkjs/mvc/simplexml/ready!"
    ], function(SearchManager) {

        // Instantiate the search manager
        var mysearch = new SearchManager({
            id: "search1",
            app: "search",
            cache: false,
            search: "index=_internal | head 50000" 
        });

        mysearch.on('search:failed', function(properties) {
            // Print the entire properties object
            console.log("FAILED:", properties);
        });

        mysearch.on('search:progress', function(properties) {
            // Print just the event count from the search job
            console.log("IN PROGRESS.\nEvents so far:", properties.content.eventCount);
        });

        mysearch.on('search:done', function(properties) {
            // Print the search job properties
            console.log("DONE!\nSearch job properties:", properties.content);
        });

    });