Detection Query Optimizer
БесплатноБез исполняемых скриптовНе проверенOptimize detection queries for performance across Splunk (SPL), Microsoft Sentinel (KQL), and Elastic Security (EQL/ES|QL). Covers search pipeline internals…
от MHaggis★ 531 звезда на GitHubОб этом скилле
Detection Query Optimizer Skill
Overview
Every SIEM processes queries differently. Understanding the execution model is essential for writing detections that run fast enough for scheduled execution without excessive resource consumption. This skill covers optimization for the three major query languages.
Set $SIEM_PLATFORM to focus guidance: splunk, sentinel, elastic
Quick Reference: Which Section?
| Platform | Query Language | Section |
|---|---|---|
| Splunk Enterprise / Cloud | SPL | SPL Optimization |
| Microsoft Sentinel / Defender | KQL | KQL Optimization |
| Elastic Security | EQL / ES|QL | EQL/ES|QL Optimization |
| Sigma | N/A | Optimization happens at the backend/compiler level. Write clean Sigma; let pySigma optimize for the target. |
SPL Optimization (Splunk)
The Splunk Search Pipeline
Every SPL search flows through these phases:
[Input] → [Parsing] → [Search (Map/Reduce)] → [Reporting] → [Output]
Phase 1: Input (Index Selection)
The search head determines which indexes and buckets to read.
Optimizations:
- Specify
index=explicitly (never rely on default index) - Specify
sourcetype=to narrow bucket scanning - Use
earliest=andlatest=to limit time range - Use
host=orsource=if applicable
// BAD — scans all default indexes
sourcetype=WinEventLog EventCode=4688
// GOOD — targets specific index
index=wineventlog sourcetype=WinEventLog:Security EventCode=4688
Phase 2: Search (Map Phase)
Indexers scan buckets and return raw events matching search terms.
Key concept: Bloom filters and tsidx. Splunk uses bloom filters for fast negative lookups and tsidx files for field indexing. Raw text terms in the search string hit bloom filters; field=value pairs hit tsidx if the field is indexed.
Optimizations:
- Put the most restrictive terms first — they filter out more events earlier
- Use indexed fields (
index,sourcetype,source,host) before extracted fields - Add raw text terms that must appear in matching events
// BAD — extracted field first, no index specification
| search process_name="powershell.exe" index=endpoint
// GOOD — indexed fields first, raw term for bloom filter
index=endpoint sourcetype=sysmon EventCode=1 powershell.exe
| where process_name="powershell.exe"
Phase 3: Reporting (Reduce Phase)
Transforming commands (stats, timechart, chart, top, etc.) aggregate results.
Optimizations:
- Push
statsas early as possible to reduce event volume - Use
byclauses to let indexers do partial aggregation - Prefer
statsovertransaction(10x+ faster for most use cases)
SPL Optimization Techniques
1. Use tstats for Data Model Searches
tstats queries accelerated data models and is dramatically faster than raw search.
// SLOW — raw search with field extraction
index=endpoint sourcetype=sysmon EventCode=1
| stats count by Image, ParentImage
// FAST — tstats against accelerated data model
| tstats count from datamodel=Endpoint.Processes
where Processes.process_name="powershell.exe"
by Processes.process_name, Processes.parent_process_name
2. Avoid Leading Wildcards
Leading wildcards (*something) defeat bloom filter optimization.
// SLOW — leading wildcard, full scan required
index=endpoint process_name=*powershell*
// FAST — trailing wildcard, bloom filter can help
index=endpoint process_name=powershell*
3. Replace Transaction with Stats
transaction is expensive because it must group events by time ordering.
// SLOW — transaction groups events by session
index=web sourcetype=access_combined
| transaction clientip maxspan=30m
// FAST — stats can achieve similar results
index=web sourcetype=access_combined
| stats earliest(_time) as start, latest(_time) as end,
values(uri_path) as pages, count
by clientip
| eval duration=end-start
4. Filter Early, Aggregate Late
Every command in the pipeline processes all events passed to it. Reduce event count as early as possible.
// SLOW — extracts fields then filters
index=endpoint sourcetype=sysmon
| rex field=_raw "CommandLine=(?<cmdline>[^\r\n]+)"
| search cmdline="*-encoded*"
// FAST — filter with raw text first, then extract
index=endpoint sourcetype=sysmon EventCode=1 "-encoded"
| rex field=_raw "CommandLine=(?<cmdline>[^\r\n]+)"
| search cmdline="*-encoded*"
5. Use Lookup Efficiently
// SLOW — lookup on every event
index=endpoint sourcetype=sysmon EventCode=1
| lookup malware_hashes hash AS SHA256 OUTPUT is_malicious
| where is_malicious="true"
// FASTER — drop unneeded fields first, then lookup
index=endpoint sourcetype=sysmon EventCode=1
| fields + SHA256, Image, CommandLine, _time
| lookup malware_hashes hash AS SHA256 OUTPUT is_malicious
| where is_malicio
Установить Detection Query Optimizer в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Detection Query Optimizer?
Optimize detection queries for performance across Splunk (SPL), Microsoft Sentinel (KQL), and Elastic Security (EQL/ES|QL). Covers search pipeline internals, common anti-patterns, and optimization techniques for detection rules on each platform.
Как установить скилл Detection Query Optimizer?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Detection Query Optimizer запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
agent-skill-stack
Find, evaluate, and assemble the smallest compatible set of AI Agent Skills for an end-to-end natural-language goal. Use when a user wants Skills for a…
от GitHubbuild-evidence-map
Build an auditable evidence map for a contested technical choice, research synthesis, proposal review, or consequential decision. Use when Copilot must…
от GitHubpinecone-rag
Build production RAG pipelines and persistent agent memory using Pinecone as the vector database backend. ALWAYS USE THIS SKILL when the user mentions…
от GitHubqdrant-monitoring-debugging
Diagnoses Qdrant production issues using metrics and observability tools. Use when someone reports 'optimizer stuck', 'indexing too slow', 'memory too high'…
от GitHub