Search properties

You can programmatically change properties on the search using the managername.settings Backbone model.

The following example shows different scenarios for updating a search manager—updating the search query, the search time range, and the value of the search manager when a timeline value changes.

<script>
    require([
        "splunkjs/mvc/searchmanager",
        "splunkjs/mvc/timelineview",
        "splunkjs/mvc/eventsviewerview",
        "splunkjs/mvc/simplexml/ready!"
    ], function(
        SearchManager,
        TimelineView,
        EventsViewerView
    ) {

        // Instantiate the search manager and views
        var mysearch = new SearchManager({
            id: "search1",
            search: "*", // Change this below
            preview: true,
            cache: true,
            status_buckets: 300
        });

        var mytimeline = new TimelineView ({
            id: "timeline1",
            managerid: "search1",
            el: $("#mytimeline")
        }).render();

        var myeventsviewer = new EventsViewerView ({
            id: "eviewer1",
            managerid: "search1",
            el: $("#myeventsviewer")
        }).render();

        // Update the search's time range
        mysearch.settings.set("earliest_time", "-12h");
        mysearch.settings.set("latest_time", "-6h");

        // Update the search query
        mysearch.settings.set("search", "index=_internal | head 2");

        // When the timeline changes, update the search manager
        mytimeline.on("change", function() {
        
        // Update the search manager with the timeline value
            mysearch.settings.set(mytimeline.val());
        });

    });
</script>

For more examples of setting search properties in views, see How to use search controls using SplunkJS Stack.