Splunk® Enterprise

Search Reference

Splunk Enterprise version 7.2 is no longer supported as of April 30, 2021. See the Splunk Software Support Policy for details. For information about upgrading to a supported version, see How to upgrade Splunk Enterprise.
This documentation does not apply to the most recent version of Splunk® Enterprise. For documentation on the most recent version, go to the latest release.

map

Description

The map command is a looping operator that runs a search repeatedly for each input event or result. You can run the map command on a saved search or an ad hoc search.

Syntax

The required syntax is in bold.

map
(<searchoption> | <savedsplunkoption>)
[maxsearches=int]

Required arguments

You must specify either <savedsplunkoption> or <searchoption>.

<savedsplunkoption>
Syntax: <string>
Description: The name of a saved search to run for each input result.
Default: No default.
<searchoption>
Syntax: search="<string>"
Description: An ad hoc search to run for each input result. For example:
...| map search="search index=_internal earliest=$myearliest$ latest=$mylatest$".
Default: No default.

Optional arguments

maxsearches
Syntax: maxsearches=<int>
Description: The maximum number of searches to run. A message is generated if there are more search results than the maximum number that you specify. Zero ( 0 ) does not equate to unlimited searches.
Default: 10

Usage

The map command is a dataset processing command. See Command types.

A subsearch can be initiated through a search command such as the map command. See Initiating subsearches with search commands in the Splunk Cloud Platform Search Manual.

Known limitations

You cannot use the map command after an append or appendpipe command in your search pipeline.

Variable for field names

When using a saved search or a literal search, the map command supports the substitution of $variable$ strings that match field names in the input results. A search with a string like $count$, for example, will replace the variable with the value of the count field in the input search result.

When using the map command in a dashboard <form>, use double dollar signs ($$) to specify a variable string. For example, $$count$$. See Dashboards and forms.

Search ID field

The map command also supports a search ID field, provided as $_serial_id$. The search ID field will have a number that increases incrementally each time that the search is run. In other words, the first run search will have the ID value 1, and the second 2, and so on.

Basic examples

1. Invoke the map command with a saved search

error | localize | map mytimebased_savedsearch

2. Map the start and end time values

... | map search="search starttimeu::$start$ endtimeu::$end$" maxsearches=10

Extended examples

1. Use a Sudo event to locate the user logins

This example illustrates how to find a Sudo event and then use the map command to trace back to the computer and the time that users logged on before the Sudo event. Start with the following search for the Sudo event.

sourcetype=syslog sudo | stats count by user host

This search returns a table of results.

User Host Count
userA serverA 1
userB serverA 3
userA serverB 2

Pipe these results into the map command, substituting the username.

sourcetype=syslog sudo | stats count by user host | map search="search index=ad_summary username=$user$ type_logon=ad_last_logon"

It takes each of the three results from the previous search and searches in the ad_summary index for the logon event for the user. The results are returned as a table.

_time computername computertime username usertime
10/12/16 8:31:35.00 AM Workstation$ 10/12/2016 08:25:42 userA 10/12/2016 08:31:35 AM

(Thanks to Splunk user Alacercogitatus for this example.)

See also

Commands
gentimes
search
Last modified on 22 November, 2022
makeresults   mcollect

This documentation applies to the following versions of Splunk® Enterprise: 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.7, 7.0.8, 7.0.9, 7.0.10, 7.0.11, 7.0.13, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.1.10, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.2.10, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6, 7.3.7, 7.3.8, 7.3.9, 8.0.0, 8.0.1, 8.0.2, 8.0.3, 8.0.4, 8.0.5, 8.0.6, 8.0.7, 8.0.8, 8.0.9, 8.0.10


Was this topic useful?







You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters