How to Configure Opensearch Slow Query Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up the opensearch slow query log by setting index time limits. The search engine then records any search that runs past your chosen threshold. Most teams enable these rules to find bad searches after a cluster slows down. Still, broad cluster roles often let users change index settings or run heavy searches. One bad search can lock up memory before the log even writes to disk. How the opensearch slow query log works The search engine breaks every search request into two distinct steps

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up the opensearch slow query log by setting index time limits. The search engine then records any search that runs past your chosen threshold. Most teams enable these rules to find bad searches after a cluster slows down. Still, broad cluster roles often let users change index settings or run heavy searches. One bad search can lock up memory before the log even writes to disk.

How the opensearch slow query log works

The search engine breaks every search request into two distinct steps. The first step is the query phase, which finds matching items in the index. The second step is the fetch phase, which grabs the actual data from shards. You must set time limits for both phases on each index you run. The system checks these limits at the shard level, not the cluster level.

You can define four log levels for each phase of the search. These levels are warn, info, debug, and trace, and each has a time rule. When a shard takes too long, the node writes a line to disk. If you run a cloud service, you must also turn on log publishing. That step sends the local log files to your central log storage tool.

Because these rules live on the index, new indices do not inherit them. Teams use index templates to apply slow log rules to new daily indices. Without templates, your team must set up logging by hand after every index roll. You can also turn thresholds down to zero to log every single search. Doing that on a busy cluster will fill your disk in minutes.

Why teams need index level log rules

Without shard level logs, a slow dashboard is a total black box. Your app team only sees a high wait time or a failed web call. They cannot tell if one bad shard or one massive search caused the delay. The slow log tells you the exact index, shard, and search body responsible.

This data helps engineers fix bad search patterns and tune shard sizes. You can spot deep paging requests or wide text matches that burn CPU cycles. It also helps you prove whether a slow response came from the network. If the shard finishes fast, the delay lives outside the search cluster.

Native roles let you pick who can change these index settings. You can give developers read rights while keeping cluster admin rights for a few people. That stops a user from turning off logs or wiping index rules by mistake.

End-to-End Encryption + Log Aggregation & Correlation: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Where native slow logs fall short in live operations

The opensearch slow query log only tells you about problems after the fact. A single reckless search can still crash a node before anyone reads the log. Native role rules decide who can log in and which index they can read. Those rules do not check how heavy an individual search request is in flight.

There is another risk when you turn on slow logs for shared indices. The log file records the full raw search text sent by the user. If a user searches for a phone number or email, that text enters the log. Now your log storage holds raw personal data that anyone with log access reads.

In the same way, developers running live fixes often get broad read roles. Those roles return full documents containing emails, card numbers, or national IDs. Native logging and role tools cannot rewrite matched fields in results on the fly. They also cannot ask a team lead to approve a risky cluster update first.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Does the opensearch slow query log track the whole cluster at once?

No, you set up slow query logs on each index one by one. To cover a whole cluster, you must apply the settings across all indices and templates.

What is the difference between the query phase and the fetch phase?

The query phase checks the index to find matching document IDs and score them. The fetch phase reads the full document content from disk for those matching IDs.

Does turning on the slow query log hurt cluster speed?

Setting normal time limits adds almost no load to your search nodes. Still, setting the limit too low writes huge log files and slows down disk writes.

The query runs. The emails stay hidden.