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!

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...