Finding slow OpenSearch queries with Query Insights

Query Insights shows which queries are slowest or most resource-intensive on your OpenSearch cluster, groups similar query shapes and displays live in-flight searches. This page explains how to use it and what to confirm before relying on it.

On this page

Why slow OpenSearch queries are hard to find without Query Insights

A team sees CPU on its OpenSearch data nodes climb over several weeks, search latency drifts upward, and nothing in the last deployment explains it. The cluster health is green and no index policy has failed, so the instinct is to add nodes. Without a record of which queries consume the most time and resources, that guess is expensive and often wrong. Query Insights exists to answer the narrower question first: which query shapes are costing the cluster the most. Introduced in OpenSearch 2.12 and included by default, it identifies the slowest or most resource-intensive queries, groups similar query structures so that one pattern repeated thousands of times is visible as one item, and shows queries that are still running. Confirm that the feature is enabled and collecting data on your version before you rely on it during an incident.

Teams usually need this when the slowdown is gradual, when several applications share one cluster, or when a single client occasionally sends an expensive aggregation that drags down everyone else. Slow query logs answer the question for one index at a time and do not group similar queries across the cluster, so they make pattern hunting slow. Query Insights gives you the ranking and the grouping in one place, and the live view helps when a query is still running and consuming resources. Ask your platform owner which top N view, which resource metrics and which retention settings are configured, since the defaults may not match your workload.

Query Insights does not replace the fixes that most slow queries eventually need. It will show that a wildcard query or a deep aggregation on a high-cardinality field is expensive, but it will not redesign your mappings, add the right field types, or decide whether the cluster has enough heap, shards and nodes for its data volume. Treat it as the step that tells you where to look. The fix may be a query change, a mapping change, a shard or node sizing decision, or a limit on the client that sends the query, and each of those needs its own owner and test. Plan the rollout so that findings from the dashboard feed a documented change process, not an ad hoc tuning session.

How top queries, grouping and live views fit together

A search request enters through a coordinating node, fans out to the data nodes that hold the relevant shards, and returns to the client. Query insights observes that work along the way and sends three views to the same dashboard: the slowest or most resource-intensive queries, similar queries grouped by structure, and queries still running. Start at the dashboard, then check whether a single expensive query shape dominates the top list or whether many small variations of one pattern add up to the load.

How one search request feeds the three query insights views.

Which Query Insights view answers which question

This table matches each Query Insights view to the question it answers, the symptom that points to it, and the check to run next. Use it to pick the starting view before drilling into individual queries. The main takeaway is that latency, resource and grouping views answer different questions, so a slow dashboard and a hot node often need different views.

ViewQuestion it answersSymptom it fitsCheck next
Top N queries by latencyWhich queries took the longest elapsed time?Users report slow searches or dashboards that load slowlyCompare the slowest queries' index targets, time ranges and aggregations, then confirm whether they run at the same times as the complaints
Top N queries by CPUWhich queries consumed the most CPU?Nodes show sustained high CPU even when individual requests look fastCheck whether a few expensive queries repeat often, and whether they run on the same data nodes
Top N queries by memoryWhich queries used the most memory?Heap pressure or circuit breaker activity without a clear latency spikeReview aggregations and sorts in the top memory queries, and confirm the field types they touch
Query grouping by similar structureWhich query shapes repeat, regardless of their literal values?One application or dashboard generates many similar requestsFind the calling application or dashboard for the top group, then decide whether the query design or the request rate needs changing
Live in-flight queriesWhat is running on the cluster right now?A slowdown is happening at this moment and history views lag behindIdentify long-running queries still executing, and check whether they should be cancelled or allowed to finish
Query Insights dashboardHow do latency, resource use and query patterns look together over time?You need a single view to show a team or to compare a period before and after a changeUse it to narrow the time window, then open the matching top N or grouping view for the detail

Latency, CPU or memory: which ranking to use in each situation

When end users report that search pages feel slow, start with the latency ranking. Latency is measured as the elapsed time a query took to complete, which is the number users feel. A query that returns in a few milliseconds on an idle node can still take seconds when it waits behind other work, so latency reflects both the query and the state of the cluster at that moment. Sort by latency, then check whether the slow queries share a structure. A single grouped query shape that appears at the top of the list across several time windows points to a specific search template, filter or sort option that the application sends. If the slow entries are scattered across many different shapes, look at cluster load in the same window rather than tuning one query.

  • Sort by latency first: Look at the top entries for the time window when users complained, not the all-time view.
  • Check the grouped shape: Confirm that the same query structure dominates, which tells you the fix belongs in the application or search template.
  • Compare against CPU: A query that is slow on latency but cheap on CPU is often waiting on I/O, locks or queued work.
  • Check the in-flight view: Live queries show whether a long-running search is still executing when users are waiting.

Confirm the fix by re-running the same grouped shape after a change and checking that its latency entries drop in the same window.

How to enable Query Insights and read the first results

This sequence confirms that your cluster can run Query Insights, turns it on if needed, produces representative load and checks that the dashboard shows top queries and query groups. Each step ends with a check you can record before you rely on the data.

  1. Confirm the cluster runs a supported version

    The platform team checks the running OpenSearch version on every node, not only the version in the deployment template. Query Insights was introduced in OpenSearch 2.12, so any cluster on 2.12 or later is a candidate. Clusters on older versions need an upgrade plan before this feature is available. Record the version from the cluster information endpoint and confirm that all nodes report the same release. The check is complete when every node reports a version at or above 2.12 and you have noted the result in your change log.

  2. Verify Query Insights is enabled

    Query Insights is included by default, so do not assume it is active. Ask the operator who owns the cluster configuration to confirm the feature state, then read the current cluster settings to see the Query Insights settings for top N queries, latency, CPU and memory. Copy setting names exactly from the Query Insights documentation rather than typing them from memory, because a misspelled key can be silently ignored. The check is complete when the settings output shows the feature enabled for the metrics you need and you have saved a copy of the current values for rollback.

  3. Confirm the cluster accepts Query Insights configuration

    Before changing anything, apply the settings through the same path your team uses for other cluster changes, such as a managed configuration file or an API call from a controlled pipeline. Set the top N collection and time window values only to what the documentation describes for your version. Review who can change these settings, since the security configuration and audit trail should record the change. The check is complete when the updated settings read back exactly as written and the audit log records the change.

  4. Generate representative query load

    Run a known set of searches that resemble production traffic, including simple term queries, filtered queries, aggregations and any sorted or paginated searches your applications issue. Use a test or staging cluster with a comparable data volume whenever possible, because results from a near-empty index will not show the expensive patterns you are looking for. Label the load run with a start and end time so you can match it to dashboard entries later. The check is complete when your load tool reports successful responses and you know the exact window in which the queries ran.

  5. Open the Query Insights dashboard

    Open the Query Insights view in OpenSearch Dashboards and select the time window that covers your load run. Confirm the view lists queries ranked by the metric you chose, such as latency, and that it is not empty because of a wrong time filter or an index pattern mismatch. If the view shows no data, check the feature settings and the cluster time zone before assuming the feature is broken. The check is complete when the dashboard displays at least one entry with a timestamp inside your load window.

  6. Verify top queries and query groups appear

    Confirm that the top queries list contains your known slow searches and that similar queries appear grouped under a shared structure rather than as separate rows. Compare the ranking against the latency or resource figures you expected from the load run. If your own queries do not appear, widen the time window, check the top N setting and confirm that the queries exceeded any threshold the configuration sets. The check is complete when at least one of your deliberately heavy queries appears in the top list and at least one group aggregates several similar requests.

  7. Record a baseline and plan the next review

    Save a screenshot or export of the first top queries and groups, together with the cluster version, the settings values and the load parameters, so later results have a comparison point. Note which queries are expensive and whether they come from applications you own, which tells you where tuning or client changes belong. Decide who reviews the list on a regular schedule and how the baseline will be stored. The check is complete when the baseline record is stored with the settings and version, and a named owner has accepted the review task.

Four ways teams misread slow query data

Query Insights shows which queries cost the most, but the data is easy to misinterpret. Each card below names one common mistake, what it leads to, and the check that prevents it before anyone changes a query or resizes a cluster.

One shape is not one user action

Query Insights groups similar query structures, so a single row can stand for thousands of requests that differ only in their filter values. Treating that group as one user action sends the team to the wrong application feature. Before changing anything, open the grouped entry, sample the individual queries it contains, and confirm which client, index pattern and time range produced the load. A group that looks expensive may be a background export job, not the search box your users rely on.

A live view is not a trend

The in-flight query view is a snapshot of what is running at one moment. A query that appears there once may be a rare outlier, while a query absent from the snapshot may still be the main cost across the day. Compare the top N results over a longer window, and record the time of each capture before drawing a conclusion. Use the snapshot to find something happening now, then confirm the pattern over time.

Load can make a query look slow

A query's latency reflects the state of the node it ran on. Heavy indexing, merges, garbage collection or other searches on the same shards can slow an ordinary query, so its entry in the latency ranking may say more about the cluster than the query. Check node-level CPU, heap and queue behavior for the same period before blaming the query text. If the cluster was under pressure, the fix may be capacity or workload scheduling rather than rewriting the search.

Mapping and shards come first

Teams often rewrite a query before checking how the index is built. A field mapped as text where a keyword was intended, an aggregation on a high-cardinality field, or an index with too many small or oversized shards can produce a slow query that no rewrite will fix. Review the mapping of the fields in the flagged query and the shard count and size of its target indices. Change the query only after the data layout is confirmed to be sound.

How to act on a slow query without guessing

Once Query Insights shows you a slow query, the next decision is which lever to pull, and the answer depends on what the query was doing when it was expensive. Rewrite the query when one request consumes disproportionate CPU or memory compared with its peers, for example a wildcard or leading-wildcard pattern, a script, or a deep aggregation over high-cardinality fields. Change the mapping or index design when the query is reasonable but the fields are wrong for it, such as a text field used for exact filtering, a keyword field that should be numeric, or an aggregation running on a field that was never indexed for that purpose. Adjust routing or shard count when a query touches far more shards than its result needs, or when a few shards hold most of the load. Each option changes a different part of the system, so write down the single hypothesis you are testing before you change anything, and compare the grouped query latency and resource numbers before and after.

Some slow queries have no good query fix. If many unrelated query shapes are slow at the same time, or the same heavy query runs at peak hours and its cost grows with data volume, the cause is usually capacity: heap sizing, too few data nodes, disk pressure or uneven shard allocation. Rewriting queries under those conditions only moves the bottleneck. Watch for the symptoms that connect Query Insights to other problems. Repeated circuit breaker exceptions point to heavy aggregations and field data use on the heap, which is covered in the circuit breaker topic. Searches that are cancelled under load point to search backpressure, which scores expensive requests by CPU, heap and elapsed time. In those cases, confirm the node-level picture before you tune individual queries, because a query fix applied to a saturated node may not change what users see.

Treat any change as a controlled test in a non-production copy of the cluster, using the same index sizes and a replay of representative traffic where you can get one. Confirm with your platform team which query types are business critical and which are background jobs, because a fix that speeds up a dashboard may slow a scheduled export. Also confirm your retention settings for query insights data and who can read it, since grouped query bodies can contain user input or field values that your data handling rules cover. If the same slow pattern returns after a fix, record it, check whether the underlying index design or cluster sizing has changed, and plan a capacity review rather than repeating the same tuning cycle.

Who can see query text and what to restrict

Slow query views show more than timings. They can expose query text, field names, index names and the users or applications that ran each search. Access to the Query Insights views should be planned with the same care as access to the data the queries touch.

Query text can reveal sensitive data

Search bodies often contain literal values such as account identifiers, email addresses, customer names or internal ticket numbers. Anyone who can open the slow query list may read those values, even without access to the underlying documents. Before you grant dashboard access, review a sample of recent query text from your own cluster and decide whether it contains anything that the viewer should not see.

Query insights docs

Field names expose data structure

Even when values are hidden, field names and index names show how your data is modeled, such as patient, payment or employee fields. Restrict who can view query structure for indexes that hold regulated data. Field-level security and field masking in the Security plugin control what documents return, but you should confirm how they interact with query metadata in your version.

Confirm dashboard and API roles

Query Insights is exposed through the Dashboards application and its APIs. Confirm which roles can open the dashboard and call the query insights endpoints in your version, and whether the cluster-level permissions that cover them are separate from index read access. Test with a non-admin user before rollout, because an admin-only role mapping can hide gaps.

OpenSearch security docs

Use role-based access control

Create a dedicated role for performance analysts that grants the monitoring permissions needed for slow query views and nothing else. Map it to your identity provider group so access follows joiner and leaver processes. Keep administrator roles limited to a small named group, since administrators can change cluster settings that affect query capture.

Attribute queries to users in audit logs

Query views show which user or application issued a slow search. Enable audit logs in the Security plugin so you can tie a slow query to an authenticated identity and time, and set retention that matches your investigation and compliance needs. Confirm which request categories your version records before you rely on them for investigations.

Restrict who can change capture settings

Query Insights collection and retention settings determine how much query detail is stored and for how long. Limit write access to these settings to the platform team and record changes. Storing query text for a long period increases exposure, so agree on a retention period with your security and privacy owners before enabling broader collection.

What to confirm about versions, data retention and overhead before production use

Before you rely on Query Insights for production decisions, confirm that your exact OpenSearch version includes it and that the version is still under maintenance. The feature was introduced in OpenSearch 2.12 and is included by default, but your cluster may run a later or earlier build, and the release policy determines what support you can expect. Under that policy, a version stays in maintenance until the next major version enters maintenance or one year passes, whichever is longer, and maintenance releases carry bug fixes and security patches but no new features. Check the OpenSearch releases page for the current status of your line, and confirm that the Query Insights dashboard ships in the OpenSearch Dashboards build you run, since the dashboard and the API can be deployed at different levels in your stack.

Next, confirm how long collected query data is kept and where it lives. Query Insights keeps top N and in-flight information in cluster memory and in the data it exposes through its APIs, so ask the vendor documentation for your version how records are retained, how the top N window is sized, and whether any data is written to an index you must manage, back up or purge. Treat that answer as a retention decision: if the data contains query text, it may hold sensitive values, so confirm who can read it through the Security plugin roles and whether audit logging captures access to it.

Finally, measure the overhead on your own hardware before enabling collection cluster-wide. Collection adds work to every search, so run a controlled test on a non-production cluster with a representative query mix, and compare latency and CPU on data nodes with and without it. Also test rolling upgrades: confirm how Query Insights settings and collected data behave on nodes running mixed versions during the upgrade, and whether the dashboard remains compatible with the cluster version at each step. Ask your support provider to put these checks in the written scope so the results are recorded before production use.

Questions teams ask before bringing in outside help

What does it cost to set up Query Insights in-house versus with a partner?

Query Insights is included by default in OpenSearch 2.12 and later, so the software itself adds no license cost. The spend is labor: an in-house team pays engineers' time to enable the feature, collect query samples, read the dashboards and tune the cluster, while a partner bills for a written, fixed scope. Costs rise with the number of clusters, the size of the query workload, how many application teams own queries, and whether fixes go beyond diagnosis into query rewrites or cluster changes. Ask any quote to separate one-time work (baseline, findings, fixes) from recurring work (periodic reviews or retainers), and to state what happens if the scope changes. DeployOpen does not publish prices; a quote follows from the written scope.

How long does a first slow query investigation take?

The length depends on how many clusters and indexes are involved, how long the team can collect data under normal load, and how many query owners must confirm changes. The main time sinks are waiting for a representative traffic window, matching grouped query shapes to the applications that send them, and checking that a fix does not move load somewhere else. Ask for a timeline that lists the data collection window, the review sessions and the retest, and confirm that the cluster's own monitoring is available during the period. Any duration in a quote should come from the written scope, not from a general estimate.

What access and inputs does the client need to provide?

A partner needs enough access to read cluster settings, the Query Insights output and index mappings, and to make changes in a test or agreed production window. In practice that means:

  • Read access to cluster health, node stats and the Query Insights APIs or dashboard
  • Sample queries from the application teams, including the request bodies and the expected results
  • A test cluster or a change window where cluster settings can be adjusted
  • Named owners for each application who can approve query changes

Confirm how credentials are issued and revoked, and where the work runs, since the cluster stays in infrastructure the client controls.

Can our own team investigate slow queries without outside help?

Yes, if one or two engineers already know the cluster and can spend time on it. Query Insights reports the slowest or most resource-intensive queries, groups similar query structures and shows live in-flight queries, so the starting data is available without extra tooling. What usually slows an internal team is the follow-through: deciding whether a query needs a rewrite, a mapping change, a different index layout or simply more capacity, and getting application owners to act. Outside help is most useful when the team lacks time, when the workload spans many applications, or when findings must be documented for an assessor.

What changes when the OpenSearch cluster runs in a regulated environment?

Query samples often contain personal or confidential data in search terms or filter values, so the first change is how those samples are collected, stored and shared. Expect the work to include role-based access for anyone who views query text, a decision on whether query bodies are logged or redacted, and change control for every setting change, with the evidence kept for review. Confirm with your compliance team which records they need, such as the investigation log, approvals and before-and-after measurements. DeployOpen prepares systems and evidence for compliance assessments but does not issue audit reports or certifications; independent auditors and certification bodies do that.

How does a partner keep query fixes from causing new problems?

A careful engagement tests each change against a copy of the recorded workload before it reaches production, then compares latency and resource use with the baseline. Ask the partner to name the metrics it will compare, how it will recheck after the change, and who signs off. Any fix that affects search results, such as a changed analyzer or a rewritten boolean clause, needs its own relevance check owned by the application team. Confirm how rollback works and where the before-and-after data is stored.

Which Query Insights data should we ask an outside team to document?

Ask for a written record that an engineer could reuse without the partner. For a first investigation, that normally means the Query Insights settings used, the top queries by latency, CPU and memory with their grouped shapes, the owner and decision for each, the change made and the retest result. Keep this record with the cluster's runbook so future slow-query reviews start from the same baseline. Make sure the deliverable format and location are written into the scope before work begins.

How DeployOpen scopes query performance work on your cluster

DeployOpen approaches slow-query investigation as a scoped piece of work on a self-hosted OpenSearch cluster in your own infrastructure. We enable and read Query Insights against your real workload, agree what to change in writing, and hand over the findings and the operating routine your team keeps afterward.

How we scope

  • Confirm the OpenSearch version and whether Query Insights is available and enabled on your cluster.
  • Agree which indexes, applications and query types are in scope, and which latency or CPU symptoms prompted the work.
  • Record the written scope, deliverables and timeline before any configuration change touches a production cluster.

How we build

  • Enable top N collection by latency, CPU and memory, and review the grouped query shapes it produces.
  • Trace each expensive query back to its calling application, index mapping and aggregation logic.
  • Test proposed fixes such as query rewrites or mapping changes on a non-production copy before rollout.

How we hand over

  • Deliver a findings document listing each slow query group, its evidence, the proposed fix and its expected effect.
  • Provide saved Query Insights dashboard views and the settings used, so your team can reproduce the analysis.
  • Walk your operators through a routine for reviewing live in-flight queries and recurring top N reports.

How we support

  • Engagements are fixed-scope, with follow-up items recorded in the same written agreement.
  • Ongoing tuning, version upgrades and continuous review of query performance are available as a retainer.
  • Ask any partner to confirm how they handle Query Insights settings, data retention and access to query text in your environment.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.