Splunk Search

how to create splunk custom search command with java ?

kalyani_y
Explorer

hi

I am trying to create a new custom search command with java, but I only found stuff related to python. Is it possible to create a custom search command with java?

0 Karma

spammenot66
Contributor

Does anyone know if this is possible. Based on the documentation, I don't think it's possible to create a custom search command in Java. It would have to be done with python

custom command documentation for python: 

https://dev.splunk.com/enterprise/docs/devtools/customsearchcommands/customsearchcmdexamples/

I went through the docs for Java and there's nothing in regards to custom commands

https://dev.splunk.com/enterprise/docs/devtools/java/plugin-eclipse/howtouseeclipse

 

splunk employees, can you help confirm? 

0 Karma

koshyk
Super Champion

You need to use Splunk Java SDK. Very good documentation at: Splunk Java SDK documentation

The core logic being..

// Create the job
JobArgs jobArgs = new JobArgs();
jobArgs.setEarliestTime("rt-1m");
String mySearch = "search index=_internal";
Job job = service.search(mySearch, jobArgs);
// View the results--a stream of previews--using standard Java classes
JobResultsPreviewArgs previewArgs = new JobResultsPreviewArgs();

    InputStream stream = job.getResultsPreview(previewArgs);
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }

kalyani_y
Explorer

hi koshyk
Thnx. i tried that one too but my requirement is i need to process those results and post back to splunk preview and this search has to work dynamically that means the input has to come from splunk search bar. this entire work has to be done with java

koshyk
Super Champion

don't think i quite understood. Is this what you are trying to do ?
- run search1 & get results of search1
- create search2 with results of search1

(you said, you got examples in python. if you put that, i might look to convert to java)

0 Karma

kalyani_y
Explorer

I need the following to be converted to java and run in splunk

Thanks InAdvance

http://docs.splunk.com/Documentation/Splunk/6.2.4/AdvancedDev/SearchScripts

0 Karma

koshyk
Super Champion
0 Karma

kalyani_y
Explorer

I need those in Java. Even though i convert code i don't have an idea whether it works or not

jagadeeshm
Contributor

any luck finding out if you can create custom search commands using Java?

Get Updates on the Splunk Community!

Splunkers, Pack Your Bags: Why Cisco Live EMEA is Your Next Big Destination

The Power of Two: Splunk + Cisco at "Ludicrous Scale"   You know Splunk. You know Cisco. But have you seen ...

Data Management Digest – January 2026

Welcome to the January 2026 edition of Data Management Digest! Welcome to the January 2026 edition of Data ...

Splunk SOAR Now Available on Google Cloud Platform

We’re excited to announce that Splunk SOAR is now natively available as a SaaS solution on Google Cloud ...