Getting Data In

retrieve indexes from splunk.log

tay
Explorer

Hello splunk community, 

I have this query but I would also like to retrieve the index to which the sourcetype belongs

index=_internal splunk_server=* source=*splunkd.log* sourcetype=splunkd
(component=AggregatorMiningProcessor OR component=LineBreakingProcessor OR component=DateParserVerbose OR component=MetricSchemaProcessor OR component=MetricsProcessor) (log_level=WARN OR log_level=ERROR OR log_level=FATAL)
| rex field=event_message "\d*\|(?<st>[\w\d:-]*)\|\d*"
| eval data_sourcetype=coalesce(data_sourcetype, st)
| rename data_sourcetype as sourcetype
| table sourcetype event_message component thread_name _time _raw
| stats first(event_message) as event_message by sourcetype component



any ideas ?
thx in advance

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

I try to avoid join where possible, but I can't make this query work without it.  See if this helps you.

index=_internal splunk_server=* source=*splunkd.log* sourcetype=splunkd
(component=AggregatorMiningProcessor OR component=LineBreakingProcessor OR component=DateParserVerbose OR component=MetricSchemaProcessor OR component=MetricsProcessor) (log_level=WARN OR log_level=ERROR OR log_level=FATAL)
| rex field=event_message "\d*\|(?<st>[\w\d:-]*)\|\d*"
| eval data_sourcetype=coalesce(data_sourcetype, st)
| rename data_sourcetype as sourcetype
| fields sourcetype event_message component
| join sourcetype [| tstats count where index=* by sourcetype, index 
  | fields - count ]
| table sourcetype component event_message index

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

tay
Explorer

Thanks, even if the query consumes a lot, but it works

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You can't retrieve the index from the log if it isn't there, which is the case for these events.  You'll have to search for the index by sourcetype.

| tstats count where index=* sourcetype=data_sourcetype
| fields - count
---
If this reply helps you, Karma would be appreciated.

tay
Explorer
This is precisely my problem, I have to start from this command and therefore retrieve the index elsewhere... but then what happens if the indexes have sourcetype names in common?
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Nothing "happens".  It's legitimate for a sourcetype to be present in more than one index.  It may complicate your query, though.

---
If this reply helps you, Karma would be appreciated.
0 Karma

tay
Explorer

so if I do a "join" with your query, the correct index will be associated with the sourcetype?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I try to avoid join where possible, but I can't make this query work without it.  See if this helps you.

index=_internal splunk_server=* source=*splunkd.log* sourcetype=splunkd
(component=AggregatorMiningProcessor OR component=LineBreakingProcessor OR component=DateParserVerbose OR component=MetricSchemaProcessor OR component=MetricsProcessor) (log_level=WARN OR log_level=ERROR OR log_level=FATAL)
| rex field=event_message "\d*\|(?<st>[\w\d:-]*)\|\d*"
| eval data_sourcetype=coalesce(data_sourcetype, st)
| rename data_sourcetype as sourcetype
| fields sourcetype event_message component
| join sourcetype [| tstats count where index=* by sourcetype, index 
  | fields - count ]
| table sourcetype component event_message index

 

---
If this reply helps you, Karma would be appreciated.

PickleRick
SplunkTrust
SplunkTrust

Probably append with some stats values() would do the trick similarily to join.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

    Thursday, June 25, 2026  |  11AM PDT / 2PM EDT  Duration: 1 Hour (Includes live Q&A) Register to ...

Analytics Workspace deprecation

As of Splunk Cloud Platform 10.4.2604 and Splunk Enterprise 10.4, Analytics Workspace is now deprecated. ...

Splunk Developer Day Recap: Building, Publishing, and Growing on the Splunk Platform

Splunk Developer Day brought the Splunk developer community together for a practical look at what it means to ...