Lesson 200.2 Basic Searching
Lesson 200.2 Basic Searching
2 Basic Searching
Learning Objectives
At the end of this lesson, learners will be able to:
● Describe adding data to Splunk.
● Run basic searches.
● Set the time range of a search.
● Identify the contents of search results.
● Refine searches.
● Use the timeline.
● Use time modifiers.
● Control a search job.
● Save search results.
Introduction
This lesson will introduce you to basic search concepts with Splunk. After a
brief introduction on how data enters Splunk, we will focus on
understanding and using the search interface, working with the time
picker, identifying the contents of the search results, and using various
tools to refine and control Splunk searches.
Happy Splunking!
2.0 Adding Data to Splunk
Splunk supports a wide range of data types, including
logs, metrics, and events, and can handle both
structured and unstructured data.
image: Freepik.com
2.0 Adding Data to Splunk (continued)
Adding data to Splunk involves sending the data to be indexed by Splunk.
There are several methods available for adding data to Splunk, including using the Splunk
Web interface, the Splunk command-line interface, or by configuring data inputs to
automatically collect data from various sources.
The OR operator is used to search for results that match at least one of the conditions or
key-value pairs.
For example, if we want to search for events that contain either "error" or "warning," we
can use the OR operator as follows:
The NOT operator is used to exclude results that match a certain condition or key-value
pair.
For example, if we want to search for events that contain "error" but not "database," we
can use the NOT operator as follows:
● It uses machine learning algorithms to analyze the data in real time and suggests
potential search terms, field names, and command options.
● It is a useful tool for beginners who may not be familiar with the search language or
for more experienced users who want to speed up their searches and discover new
fields and commands.
● Restricting, or filtering your search criteria using a time range is the easiest and most
effective way to optimize your searches.
● You can use time ranges to troubleshoot an issue if you know the approximate time
frame when the issue occurred. Narrow the time range of your search to that timeframe.
○ For example, to investigate an incident that occurred sometime in the last hour, you can
use the default time range: “Last 24 hours,” but a better option is Last 60 minutes.
● Use the Time Range Picker to set a time range for a search.
○ Presets
○ Relative
○ Real Time
○ Date Range
○ Date and Time Range
○ Advanced
● The interface provides many different tools for selecting the time range
such as Presets, Relative, Real-time, Date Range, and more.
● The List display option shows the event information in three columns.
image: https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchTutorial/Startsearching
● The Timeline of events is a visual representation of the number of events that occur at
each point in time.
● As the timeline updates with your search results, there are clusters or patterns of bars.
The height of each bar indicates the count of events.
● Peaks or valleys in the timeline can indicate spikes in activity or server downtime. The
timeline highlights patterns of events, or peaks and lows in event activity.
● The timeline options are located above the timeline. You can zoom in, zoom out, and
change the scale of the timeline chart.
Source: https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchTutorial/Startsearching
● When you run a search, the fields are identified and listed in
the Fields sidebar next to your search results. The fields are
divided into two categories.
● You can hide the fields sidebar to maximize the results area.
Source: https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchTutorial/Startsearching
image: screenshot, splunk Search & Reporting app
2.3 Identify the Contents of Search Results
Understanding Search Results - Patterns, Statistics, and Visualizations (continued)
● The Patterns tab displays a list of the most common patterns among the set of
events returned by your search. Each of these patterns represents events that share a
similar structure.
● The Statistics tab populates when you run a search with transforming commands
such as stats, top, chart, and so on.
● Searches with transforming commands also populate the Visualization tab. The
results area of the Visualizations tab includes a chart and the statistics table that is
used to generate the chart. You will learn about transforming commands, and use the
Statistics and Visualizations tabs later.
Source: https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchTutorial/Startsearching
The Timeline of events, the Fields sidebar, and the Events viewer are
important components that aid in searching and analyzing data in Splunk.
This can be done by adding more search terms, using filters, and refining search
syntax.
Different search modes in Splunk affect the way results are returned.
Refining searches can also help to eliminate irrelevant data or false positives,
leading to more efficient and accurate analysis.
Basic ways to refine a search include drill-down into the search results, using
different search modes, and comparison operators.
2.5 Use the Timeline
Use the timeline to investigate events-
The timeline is a visual representation of the number of events in your search
results that occur at each point in time.
The timeline shows the distribution of events over time.
When you use the timeline to investigate events, you are not running a new search; you
are filtering the existing search results.
You can use the timeline to highlight patterns or clusters of events or investigate
peaks (spikes in activity) and lows (possible server downtime) in event activity.
Position your mouse over a bar to see the count of events. Click on a bar to drill down
to that time range.
2.5 Use the Timeline
Change the timeline format-
The timeline is a visual representation of the number of events in your search
results that occur at each point in time.
The timeline shows the distribution of events over time.
When you use the Zoom In/Out to Selection buttons, Splunk will run a new search with a new time
frame.
It shows the distribution of events over a period of time and allows the user
to easily identify patterns and trends.
Selecting a time range on the timeline will filter the events on the search
results without running a new search. Zooming in or zooming to a selection
will run a new search.
When searching or saving a search, you can specify absolute and relative time ranges using
time modifiers.
● An absolute time range uses specific dates and times (e.g., from 12 A.M. April 1, 2023 to
12 A.M. April 13, 2023).
● A relative time range is dependent on when the search is run. For example, a relative
time range of -60m means 60 minutes ago. If the current time is 3 P.M., the search
returns events from the last 60 minutes, or 2 P.M. to 3 P.M. today.
● A time range that you specify in the Search bar, or in a saved search, overrides the time
range that is selected in the Time Range Picker.
● If you specify a time range of Last 24 hours in the Time Range Picker and in the Search
bar you specify earliest=-30m latest=now, the search only looks at events that have a
timestamp within the last 30 minutes.
● This applies to any of the options you can select in the Time Range Picker.
● Time ranges that you specify directly in the Search bar apply only to that portion of the
search.
○ The time ranges specified in the main search do not apply to subsearches.
○ Time time ranges specified in a subsearch applies only to that subsearch. The time
range does not apply to the main search or any other subsearch.
○ source: https://docs.splunk.com/Documentation/Splunk/9.0.4/Search/Specifytimemodifiersinyoursearch
Use Time Modifiers in Your Search (continued)
Specify absolute time ranges-
● For exact time ranges, the syntax for the time modifiers is %m/%d/%Y:%H:%M:%S.
● The following search specifies a time range from 12 A.M. April 19, 2023 to 12 A.M. April 27,
2023.
○ earliest=04/19/2023:00:00:00 latest=04/27/2023:00:00:00
● If you specify only the earliest time modifier, the latest is set to the current time now by
default.
● If you specify a latest time modifier, you must also specify an earliest time.
image: screenshot,
splunk Search &
Reporting app
source: https://docs.splunk.com/Documentation/Splunk/9.0.4/Search/Specifytimemodifiersinyoursearch
Use Time Modifiers in Your Search (continued)
Specify relative time ranges-
source: https://docs.splunk.com/Documentation/Splunk/9.0.4/Search/Specifytimemodifiersinyoursearch
Use Time Modifiers in Your Search (continued)
Relative time modifiers that snap to a time-
● With relative time, you can specify a snap to time, which is an offset from the relative
time.
● The snap to time unit rounds down to the nearest or latest time for the time amount
that you specify.
● To do this, separate the time amount from the snap to time unit with an "@" character.
○ For example, the current time is 15:45:00 and the snap to time is earliest=-h@h.
The time modifier snaps to 14:00.
● You can also define the relative time modifier using only the snap to time unit. To snap to
a specific day of the week, use @w0 (or @w7) for Sunday, @w1 for Monday, and so
forth.
● To search for events in the previous month, specify earliest=-mon@mon latest=@mon.
This example begins at the start of the previous month and ends at the start of the
current month.
source: https://docs.splunk.com/Documentation/Splunk/9.0.4/Search/Specifytimemodifiersinyoursearch
Use Time Modifiers in Your Search - Summary
An absolute time range refers to a specific range of time that is defined by a start time and an
end time, in a specific date and time format:
● earliest=04/19/2023:00:00:00 latest=04/27/2023:00:00:00
A relative time range, is a range of time that is defined in relation to the current time or to a
specific time point. This type of range is usually defined using time units such as minutes,
hours, days, or weeks, and can be expressed as a positive or negative value.
Snap to time is an offset from the relative time and rounds down to the nearest or latest
time for the time amount that you specify using the "@" character.
The default lifetime is 10 minutes. The lifetime starts from the moment the job is run.
source: https://docs.splunk.com/Documentation/Splunk/9.0.4/Search/Aboutjobsandjobmanagement
2.7 Control a Search Job - Summary
A search job is the process of executing a search request and retrieving the
results.
When you initiate a search in Splunk, it creates a search job that runs in the
background to fetch and process the data, while this is happening, you can stop
or pause the process.
The Search Job Inspector, Job Details dashboard, Jobs manager page,
and the Job menu allow you to inspect and manage search jobs.
The Edit search job settings, option allows you to share the job, edit the job’s
permissions, and change the job’s lifetime.
The default lifetime of a job is 10 minutes. Using the job settings menu you
can extend the job’s lifetime to 7 days.
2.8 Save Search Results
In Splunk, users have the option to save
search results for later use or to share
with others.
Saving search results allows users to
easily access relevant data without
having to re-run the search.
A user can also export the search results
in several different formats.
image: Freepik.com
2.8 Save Search Results (continued)
Saving the search results.
There are several ways to save search
results in Splunk.
Using the Save As drop-down menu, any
search can be saved as a Report or an
Alert.
Search results (especially searches that
include statistical analysis) can, via this
menu, serve as data drivers for new or
existing Dashboards.
We will cover Reports, Alerts, and
Dashboards in more detail later in this
course.
image: https://docs.splunk.com/Documentation/Splunk/9.0.4/Search/Savingsearches
2.8 Save Search Results (continued)
Export the search results.
To export the search results to a file, use the Export button next to the Job toolbar.
You can also export search results to a file in any of the following formats:
● Raw events
● CSV
● XML
● JSON
Knowledge check.
● What syntax is used to link key/value pairs in search strings?
● What does the “earliest=-72h@h latest=@d” time range do?
● What is the function of the timeline located under the search bar?
● What can be configured using the Edit Job Settings menu?
● What user interface component allows for time selection?
● By default, how long does Splunk retain a search job?
● Which Boolean operator is implied between search terms, unless otherwise specified?
● What is character is used as a wildcard in Splunk?
● What the easiest and most effective way to optimize your searches?
● What is an event?
● What are the three search modes in Splunk?