Splunksplunkfield-extractionregexlookupproduction-ready

Field Extraction and Enrichment

SPL patterns for extracting structured fields from unstructured logs, enriching events with lookup tables, and normalizing data.


title: "Field Extraction and Enrichment" description: "SPL patterns for extracting structured fields from unstructured logs, enriching events with lookup tables, and normalizing data." category: "Splunk" language: "spl" tags: ["splunk", "field-extraction", "regex", "lookup", "production-ready"] createdAt: "2025-04-10" updatedAt: "2025-04-25"

Overview

Patterns for extracting structured fields from unstructured logs using regex, enriching events with external lookup tables (CSV), and normalizing inconsistent field formats across different log sources into a unified schema.

Code

| rex field=_raw "duration=(?<duration_ms>\d+)ms"
| lookup service_owners.csv service_name OUTPUT team, oncall_email
| eval normalized_status=case(status="OK", 200, status="Error", 500)

Notes

  • Named capture groups in rex create new searchable fields at search time
  • Use spath for JSON field extraction instead of regex (faster and more reliable)
  • Lookup tables (CSV files) enrich events with metadata not present in logs
  • cidrmatch identifies internal vs external traffic without maintaining IP lists
  • Field normalization with case() handles inconsistent formats from different services
  • Consider REPORT transforms in props.conf for high-volume extraction at index time