Splunk Search

Deleting several saved searches in one call

strive
Influencer

Hi,

I am using Splunk REST API to delete saved searches in my java program. I would like to delete several saved searches in one call. Is it possible?

I tried something like:
DELETE saved/searches/{name,name1,name2}

and it did not work.

Thanks

Strive

Tags (1)
1 Solution

Damien_Dallimor
Ultra Champion

No , you can only delete 1 Saved Search per HTTP DELETE request to the REST endpoint

But you could easily write your own wrapper method using the Java SDK, albeit several HTTP calls will still be getting invoked in the background.

public void deleteSavedSearches(List<String>savedSearchNames){

    Map<String, Object> connectionArgs = new HashMap<String, Object>();
    connectionArgs.put("host", "mysplunkserver");
    connectionArgs.put("username", "fred");
    connectionArgs.put("password", "flintstone");

    Service splunkService = Service.connect(connectionArgs);

    SavedSearchCollection savedSearches = splunkService.getSavedSearches();

    for(String savedSearchName:savedSearchNames)
        savedSearches.remove(savedSearchName);

}

View solution in original post

0 Karma

Damien_Dallimor
Ultra Champion

No , you can only delete 1 Saved Search per HTTP DELETE request to the REST endpoint

But you could easily write your own wrapper method using the Java SDK, albeit several HTTP calls will still be getting invoked in the background.

public void deleteSavedSearches(List<String>savedSearchNames){

    Map<String, Object> connectionArgs = new HashMap<String, Object>();
    connectionArgs.put("host", "mysplunkserver");
    connectionArgs.put("username", "fred");
    connectionArgs.put("password", "flintstone");

    Service splunkService = Service.connect(connectionArgs);

    SavedSearchCollection savedSearches = splunkService.getSavedSearches();

    for(String savedSearchName:savedSearchNames)
        savedSearches.remove(savedSearchName);

}
0 Karma

strive
Influencer

After we found out that it is not possible, we implemented it like how you have mentioned. Thank you Damien.

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...