Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Export search, no job SID is returned , synchronous
*/
public static void exportSearchExample() {
Service splunkService = connectAndLoginToSplunkExample();
String searchQuery = "search index=_internal * | head 10";
JobArgs queryArgs = new JobArgs();
queryArgs.setEarliestTime("-1d@d");
queryArgs.setLatestTime("now");
// perform the export
InputStream stream = splunkService.export(searchQuery, queryArgs);
//use MultiResultsReader where processing results from export searches,
//which might return one or more previews before returning final results.
MultiResultsReaderXml multiResultsReader = null;
try {
// Display results using the SDK's multi-results reader for XML
multiResultsReader = new MultiResultsReaderXml(stream);
int counter = 0; // count the number of events
for (SearchResults searchResults : multiResultsReader) {
for (Event event : searchResults) {
System.out.println("***** Event " + counter++ + " *****");
for (String key : event.keySet())
System.out.println(" " + key + ": " + event.get(key));
}
}
} catch (IOException e) {
} finally {
if (multiResultsReader != null)
try {
multiResultsReader.close();
} catch (IOException e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.