Skip to content

Lesson 7 of 9 · 22m

Search Patterns That Scale Under Pressure

Time windows, field selection, filters versus queries, and the habits that keep incident searches fast instead of theatrical.

During an outage nobody wants a clever query. They want the right ten thousand events, quickly, in the right order, without melting the cluster. Search performance is mostly discipline: narrow the time, narrow the stream or index, filter on indexed fields, and scan text last.

Elasticsearch: filter before you query

In query DSL, filter clauses are non-scoring and cacheable; must clauses calculate relevance. For logs, relevance is usually irrelevant.

GET logs-app-*/_search
{
  "size": 100,
  "sort": [{"@timestamp": "desc"}],
  "query": {
    "bool": {
      "filter": [
        {"range": {"@timestamp": {"gte": "now-30m"}}},
        {"term": {"service.name": "checkout"}},
        {"terms": {"log.level": ["error", "fatal"]}}
      ],
      "must": [
        {"match_phrase": {"message": "payment authorization expired"}}
      ]
    }
  }
}

The order in JSON is not the execution order, but the intent matters: use indexed exact fields to reduce candidates before the analyzed text scan.

Kibana habits that hide footguns

  • Set the time picker before searching, not after staring at an empty histogram.
  • Pin filters for service and environment once; carry them through the investigation.
  • Search for stable fragments, not punctuation-heavy full messages.
  • Use trace_id pivot links when tracing exists.

A query like error across all indices for twenty-four hours is not investigative rigor. It is cluster abuse.

Loki: selector first, pipeline second

{service="checkout", environment="prod"}
  |= "authorization expired"
  | json
  | latency_ms > 500

The stream selector determines which chunks are opened. Everything after it is scan work. This is why a narrow selector beats a sophisticated pipeline.

Know your ordering guarantees

Search results can include duplicate ingest, retries, out-of-order events, and clock skew. @timestamp descending is useful, but for exact reconstruction use sequence fields, trace/span IDs, or host-local ordering when available. Do not build forensic conclusions on millisecond ordering across unrelated machines without checking clock synchronization.

Field notes

  • The first query of an incident should answer "where is it loud?" not "give me every error in the company."
  • Aggregations are often faster than scrolling raw events when you are still orienting.
  • Beware leading wildcards and broad regexes. They disable the index structures that make search fast.
  • Save useful queries with names. Incident adrenaline makes people reinvent worse queries.

Was this lesson helpful?

Sign in to rate