A subsearch is a search that runs within another search, and provides input to the outer search. A subsearch is useful when the input to the outer search is not known in advance, but depends on the results of another search. A subsearch is also useful when the input to the outer search is too large to be specified manually, but can be generated by another search. Therefore, a subsearch is the most appropriate in the scenario when dynamically filtering hosts. For example, if we want to filter the hosts that have a certain value of a field, we can use a subsearch to find those hosts and pass them to the outer search. For example:
This search will return the events from the main index that have a host value that matches the subsearch. The subsearch will find the hosts that have more than 100 events with status 404 in the access_combined sourcetype, and pass them to the outer search as a list of values. This way, we can dynamically filter the hosts based on another search criterion.
The other scenarios are not as suitable for using a subsearch. When joining results from multiple indexes, we can use the join command or append command instead of a subsearch. When filtering indexed fields, we can use the where command or the search command instead of a subsearch. When joining multiple large datasets, we can use the map command or the multisearch command instead of a subsearch.
References:
Splunk Core Certified Consultant Test Blueprint
Splunk Documentation: About subsearches
Splunk Documentation: Use subsearches