The Slow Log in Elasticsearch

The Slow Log in Elasticsearch

A complete, friendly guide to the built-in diary that catches slow searches and slow document writes, how to switch it on, how to read every line it writes, and how to turn those lines into faster, cheaper, calmer clusters.

Imagine a busy restaurant kitchen. Every order ticket has a little timer. Most dishes leave the pass in six or seven minutes, and nobody thinks about them. But the head chef has one rule: any ticket that takes longer than fifteen minutes goes on a special clipboard, together with the table number, the dish, and how long it took. At the end of the week, the chef reads the clipboard and quickly sees which dishes, which cooks, and which busy hours cause the trouble.

Elasticsearch has a clipboard just like that. It is called the slow log. It quietly writes down every search and every document write that takes longer than a limit you choose, and it stays silent about everything that is fast. Without it, slowness in a large cluster is like a rumor: everyone feels it, nobody can point at it. With it, slowness becomes a list of names, times, and numbers you can act on.

In this guide you will learn what the slow log is, what it measures and what it does not, how to configure it safely, how to read each line, and how to build a habit of using it in production. You do not need any coding background. Every new word is explained the first time it appears, and each big idea comes with an everyday comparison.

1What Is the Slow Log?

The shortest possible answer: it is a set of log files where Elasticsearch records searches and document writes that were slower than a limit you set.

Let us build the definition slowly. Elasticsearch is a search and analytics engine. Companies use it to search products, explore application logs, count events, and draw charts. You send it a question, called a search request, or you send it new data, called an indexing request. Elasticsearch stores data in an index, which is like a big labeled cabinet of documents, and it slices each index into pieces called shards so the work can be shared across many servers.

A log is a diary kept by a program. Each line says what happened and when. Elasticsearch already writes a general diary about its own health, but that diary does not say which particular search was slow. The slow log fills that gap. It is a special pair of diaries, one for searches and one for indexing, that only records events that crossed a threshold. A threshold is simply a time limit, such as “five seconds.”

Everyday Analogy

Think of a race with a timekeeper at the finish line. The timekeeper does not write down every runner. Only the runners who finished slower than a set time get an entry in the notebook, along with their names and their numbers. The notebook is short, easy to read, and shows exactly who needs help. The slow log is that notebook, and each shard of your index is a timekeeper for its own track.

Two logs, not one

Elasticsearch offers two separate slow logs. The search slow log records slow searches. The indexing slow log records slow document writes. They have their own settings, their own files, and their own thresholds, because searching and writing are very different kinds of work. You can switch on one, both, or neither.

Off until you turn it on

By default, the slow log is disabled. Every threshold starts at a special value that means “never log.” This is on purpose. A slow log with no limits would log every operation, which would fill your disks and slow down the cluster. You choose the limits, and you can change them at any time without restarting anything.

2 logs
One for searches, one for document writes
4 levels
Warn, info, debug, and trace, each with its own time limit
Per shard
Each shard writes its own entries about its own work
i
Name check

You may hear “slow query log” or “slowlog” used for the same feature. The settings and log files spell it as one word, slowlog. The feature covers indexing too, so “slow log” is the more accurate name.

What the slow log is not

The slow log is not a live monitor. It writes a line only when an operation has finished, so it cannot tell you about a search that is stuck right now. It is not a profiler, so it does not explain why something was slow. It is not an alarm, so it does not send messages. It is a factual record: which index, which shard, how long, and what was asked. Everything else, such as explaining and alerting, is built on top of that record.

Where you will meet it

You will meet the slow log when a dashboard becomes sluggish and someone asks “which query is doing this?”, when a nightly data load takes twice as long as last week, when a cluster costs too much and you want to find the heaviest queries, and when a release changes the shape of your search requests and you want proof of the effect. In each case, the slow log turns a feeling into evidence.

2Why It Exists: The Problem of Invisible Slowness

A cluster can be busy and still look healthy on the surface. The slow log exists because averages hide the few requests that hurt the most.

Most monitoring shows averages: the average search time, the average indexing rate, the average CPU use. Averages are useful, but they smooth over trouble. If ninety-nine searches finish in 20 milliseconds and one takes 30 seconds, the average looks fine. Yet the user who waited 30 seconds sees a broken product, and that single search may have consumed as much CPU as the other ninety-nine combined.

The needle in a haystack

A busy cluster handles thousands of requests every second. You cannot read them all, and you should not want to. What you need is a filter that says: show me only the slow ones, and give me enough detail to recognize them. That is the job of the slow log.

Everyday Analogy

Picture a school bus company. Most buses arrive on time, and the manager does not read a report for each of them. But she asks the drivers to fill out a “late bus slip” whenever a bus is more than ten minutes behind. At the end of the week, the slips show that one route, in one neighborhood, on rainy Mondays, is always late. Without slips, that pattern would stay invisible. The slow log collects late slips for your searches.

Slowness has many possible owners

When Elasticsearch feels slow, the cause could be almost anything: one badly written query, a growing index, too many shards, a burst of writes, a garbage collection pause, a busy disk, or a noisy neighbor on shared hardware. Guessing is expensive. A slow log line points at facts that narrow the list quickly: which index was involved, how many shards, which phase was slow, and what the request looked like.

An illustrative story

FreshCart, an imaginary grocery delivery app

FreshCart runs its product search on Elasticsearch. Customer complaints say that “search is sometimes slow in the evening.” The average search time is 45 milliseconds, which looks great. The team sets the search slow log at one second and waits a day. The log shows 312 entries, and 290 of them contain the same shape of query: a wildcard search with a leading star, sent by a new “find similar products” feature. Fixing that one feature removes 93 percent of the slow entries. This story is invented to make the numbers easy, but the pattern is the one teams meet every week.

Writes can be slow too

Searches get most of the attention, but slow writes hurt as well. If documents take too long to index, data arrives late, queues grow, and dashboards show yesterday’s numbers. The indexing slow log catches writes that were slower than expected, often exposing oversized documents, huge numbers of fields, or a disk that is struggling.

A short history

The slow log has been part of Elasticsearch for many years and has grown gradually. Early versions wrote plain text lines. Modern versions write structured JSON lines that are easier for machines to read, and newer releases can add details such as which user sent the request. The core idea has not changed: a per-index, threshold-based diary of slow work.

!
Do not expect miracles

The slow log shows you where to look. It will not fix anything on its own. The value comes from reading it, finding patterns, and acting on them. A log nobody reads is only a heavier disk.

3The Building Blocks You Need to Know First

To read the slow log with confidence you need seven simple ideas: node, index, shard, search phases, indexing operation, threshold, and log level.

Node

A running copy of Elasticsearch

A node is one server process. A group of nodes working together is a cluster. Think of nodes as the branches of a library chain.

Index

A collection of similar documents

An index might hold all products or all log lines for one day. Slow log settings are chosen per index.

Shard

One slice of an index

Each shard is a small search engine of its own. The slow log measures the work done by each shard separately.

Search phases

Query then fetch

A search first finds and ranks matches, then collects the full documents. The slow log has separate limits for each phase.

Threshold

The time limit

A slow log line is written only when the work took longer than the threshold. A value of minus one means never.

Level

How serious the line is

Warn, info, debug, and trace are four severity labels. A slower operation gets a more serious label.

Primary shards and replica shards

Every shard has one primary copy, which receives new writes first, and it can have replica copies on other nodes. Replicas hold the same data and can answer searches. This matters for the slow log because each shard copy writes to the log of the node it lives on. The evidence for one slow search may be spread across several nodes, and you need to collect logs from all of them to see the whole picture.

Query phase and fetch phase

Elasticsearch normally answers a search in two steps. In the query phase, each shard figures out which documents match, counts them, ranks them, and computes any aggregations. Aggregations are Elasticsearch’s way of grouping and counting data, such as “orders per country.” The shard returns a small package of results. In the fetch phase, the coordinating node asks the shards for the full contents of the winning documents. The search slow log measures these two phases separately, so you can tell whether the finding was slow or the collecting was slow.

Who does what during a search

A search request first lands on a coordinating node. That node forwards the request to one copy of each relevant shard, waits for the partial answers, merges them, and replies to the client. In most production setups the client talks to the cluster through a load balancer or an API gateway.

flowchart LR
    A["Client application"] --> B["Load balancer or API gateway"]
    B --> C["Coordinating node"]
    C --> D1["Shard 1 on Data Node A"]
    C --> D2["Shard 2 on Data Node B"]
    C --> D3["Shard 3 on Data Node C"]
    D1 --> E["Coordinating node merges partial results"]
    D2 --> E
    D3 --> E
    E --> F["Final response to client"]
    D1 -.-> L1["Slow log entry on Node A"]
    D2 -.-> L2["Slow log entry on Node B"]
    D3 -.-> L3["Slow log entry on Node C"]
Figure 1: A search fans out to every shard. Each slow shard writes its own slow log entry on the node where it lives, not at the coordinating node.

Look closely at Figure 1. The dotted lines show that the slow log entries are written next to the shards, not at the load balancer or the coordinating node. Two consequences follow. First, one slow search can produce several log lines, one per slow shard. Second, the time you see in a line is the shard’s own working time, not the total time the client waited.

Indexing an operation

When you add or change a document, Elasticsearch sends the write to the right primary shard, which processes it and then forwards it to the replicas. Each shard copy that processes the write does its own work and can write its own slow log line. Applications often send many documents in one bulk request to save network trips. The indexing slow log still measures each document on its own, so one bulk can produce many lines or none at all.

i
Good to know

Some clusters also run ingest pipelines, which are small processing steps applied to documents before they are stored. That preparation happens before the shard starts its own work, so the indexing slow log does not include it. Chapter 5 explains what is and is not counted.

4How the Slow Log Differs From Other Diagnostic Tools

Elasticsearch offers several ways to look at performance. Each answers a different question, and using the right one saves hours.

Beginners often ask why they need a slow log when there are already statistics, monitoring dashboards, and a profiler. The answer is that each tool shows a different angle. Let us meet them one by one.

Node and index statistics

The statistics operations return counters such as the total number of searches, the total time spent searching, and the number of indexing operations. They are great for trends and averages. They cannot tell you which specific request was slow, because counters only add things up.

The profile option

A search request can ask Elasticsearch to profile itself. The response then includes a detailed breakdown of how much time each part of the query took inside each shard. Profiling is superb for understanding one query, but it only works on a request you already know about and choose to profile. It also adds some overhead, so it is not something you leave on for all traffic.

The task management operations

The tasks operations list requests that are running right now, and they can cancel some of them. They are the right tool for a stuck search. They cannot show you a search that ended an hour ago.

The hot threads operation

Hot threads takes a quick snapshot of what the busiest threads inside a node are doing at this moment. It is helpful during a live slowdown to see what the CPU is busy with, but it too is a snapshot, not a history.

Side-by-side comparison

ToolAnswers the questionTime viewNeeds you to know the request first?
Slow logWhich searches and writes were slower than my limit, and what did they look like?History, written after each slow operation finishesNo. It finds the requests for you.
Profile optionWhy is this one query slow, part by part?One request, on demandYes
Tasks operationsWhat is running right now, and for how long?LiveNo
Hot threadsWhat is the busiest code doing on this node at this moment?SnapshotNo
Statistics operationsHow much total search and indexing work has this node or index done?Counters and trendsNo
Monitoring dashboardsHow are CPU, heap, latency, and queues changing over time?Time seriesNo
Everyday Analogy

Picture a hospital. The statistics are the daily headcount at the front desk. The task list is the whiteboard showing which patients are in surgery right now. Hot threads is a nurse looking around the busiest room. The profile option is a detailed test on one patient. The slow log is the incident register, listing every case that took longer than expected, so managers can spot patterns across the whole week.

flowchart TD
    A["Users report slowness"] --> B["Monitoring dashboards: is the whole cluster stressed?"]
    B --> C["Slow log: which requests were slow?"]
    C --> D["Profile option: why was that request slow?"]
    D --> E["Fix the query, mapping, or settings"]
    E --> F["Slow log and dashboards: confirm the improvement"]
    B --> G["Tasks and hot threads: what is happening right now?"]
Figure 2: A typical investigation. Dashboards show that something is wrong, the slow log names the suspects, and the profile option explains them.

How they work together

These tools are teammates, not rivals. A healthy workflow starts wide and narrows down. Dashboards say that latency rose at three o’clock. The slow log says that a certain index and a certain query shape caused most of the slow entries. The profile option, run on a copy of that query, shows that one clause dominates the time. After the fix, the slow log goes quiet, and the dashboards confirm it.

i
Rule of thumb

Use the slow log to find the suspects, the profile option to question them, the tasks operations to catch live troublemakers, and dashboards to see the big picture. If you only have one of them, the slow log gives the best return for the least effort, because it works around the clock without anyone watching.

5What Exactly Is Measured: The Search and Indexing Slow Logs

The number in a slow log line is not the time your user waited. It is the time one shard spent on one piece of work. Knowing the difference prevents many wrong conclusions.

The search slow log

The search slow log watches the two phases of a search, one shard at a time. For the query phase, it measures how long the shard took to find, rank, and aggregate its matches. For the fetch phase, it measures how long the shard took to load the documents that were chosen. Each phase has its own set of limits, because they usually run at very different speeds. A query phase of a few hundred milliseconds may be normal, while a fetch phase of that length would be alarming.

Because the measurement is per shard, a search against an index with ten shards is judged ten separate times. Two of the ten shards may cross the limit and write lines, while eight stay quiet. The slow lines you see are the slowest pieces of the search, not necessarily the whole search.

The indexing slow log

The indexing slow log watches individual document write operations on a shard. When a shard finishes processing a document and the time it took is over the limit, a line is written. The measured time covers the shard’s own work: reading the document, applying the field rules, and adding it to the index structures. It is measured for each document separately, even when the document arrived as part of a large bulk request. Deletions are not the focus of this log; it is about writing documents.

What is counted and what is not

Part of the journeyCounted in the slow log time?Why it matters
Work a shard does in the query phaseYesThis is the main thing the search slow log measures
Work a shard does in the fetch phaseYes, under its own limitsSlow fetches often mean very large documents or many results
Time waiting in a queue before a shard startsNoA busy cluster can feel slow to users while the slow log stays quiet
Network travel between client, coordinator, and shardsNoSlow networks are invisible here
The coordinating node merging partial resultsNoHuge aggregations can be slow in the merge without any shard line
Ingest pipeline processing before an indexed writeNoSlow pipelines need their own statistics
Shard work on one document writeYesThis is the main thing the indexing slow log measures
Everyday Analogy

Think of a courier company that times only the moment the driver spends at the customer’s door, from knocking to handing over the parcel. It does not time the wait at the warehouse, the traffic on the road, or the sorting at the depot. A parcel can still arrive late even when every door time is short. The slow log is the door timer. It is precise, but it is only one part of the delivery.

sequenceDiagram
    participant C as Client
    participant N as Coordinating node
    participant S as Data node shard
    participant L as Slow log file
    C->>N: Search request
    N->>S: Run the query phase
    S->>S: Find, rank, and aggregate
    S->>L: Write a line if the time is over a query limit
    S-->>N: Partial result
    N->>S: Run the fetch phase for chosen documents
    S->>S: Load documents
    S->>L: Write a line if the time is over a fetch limit
    S-->>N: Documents
    N-->>C: Merged response
Figure 3: The shard measures its own work in each phase and writes to its local slow log. Waiting, travel, and merging are outside the measurement.

Why this matters in practice

If users complain about slowness but the slow log is empty, do not conclude that nothing is wrong. The delay may be in the queue, the network, the coordinating node, the client application, or an ingest pipeline. Thread pool queues and rejected requests, which are visible in statistics and monitoring, are the usual next place to look. The slow log is powerful but narrow, and treating it as the whole truth is a classic mistake.

!
Watch out

A line in the slow log is written only after the operation finishes. A request that hangs for an hour will not appear until it ends, if it ever does. For requests that are stuck right now, use the tasks operations.

6Thresholds and Levels: How Elasticsearch Decides to Write a Line

Every slow log line comes from a simple comparison: the measured time against a set of limits. Understanding the rule makes the settings easy to plan.

For each kind of measurement, you can set up to four thresholds, one for each log level: warn, info, debug, and trace. A log level is a label that says how serious or how detailed a line is. Usually, warn is the most serious and trace is the most detailed. In the slow log, the four levels act as four tiers of slowness.

The rule

When an operation finishes, Elasticsearch compares its time against the thresholds, starting from the most serious level. If the time is greater than or equal to the warn threshold, the line is written at the warn level. If not, it checks the info threshold, then debug, then trace. The first one that matches decides the level of the line, and only one line is written per operation. If the time is below every threshold, nothing is written.

That means you should usually set the warn threshold as the largest number and trace as the smallest. For example, warn at ten seconds, info at five, debug at two, and trace at half a second. A search that takes seven seconds gets an info line. One that takes twelve seconds gets a warn line. One that takes one second gets nothing.

flowchart TD
    A["Operation finishes with a measured time"] --> B{"Time at or above the warn limit?"}
    B -->|Yes| W["Write the line at warn level"]
    B -->|No| C{"Time at or above the info limit?"}
    C -->|Yes| I["Write the line at info level"]
    C -->|No| D{"Time at or above the debug limit?"}
    D -->|Yes| G["Write the line at debug level"]
    D -->|No| E{"Time at or above the trace limit?"}
    E -->|Yes| T["Write the line at trace level"]
    E -->|No| N["Write nothing"]
Figure 4: The slowest tier that matches decides the level. Fast operations produce no line at all.

Special values

  • Minus one switches a threshold off. This is the default for all of them, which is why a fresh cluster writes no slow log lines.
  • Zero milliseconds means “log everything at this level.” This is useful for a short experiment, because it captures every operation. It is dangerous to leave on, because the volume can be enormous.
  • Time units such as 500ms, 2s, and 1m are all accepted, so you can write limits the way you speak.
Everyday Analogy

Consider the warning lights on a car dashboard. A yellow light means “check soon,” an orange light means “check today,” and a red light means “stop now.” The car does not show three lights at once. It shows the most serious one that applies. The slow log levels work the same way: the slowest tier reached is the label of the line.

Why four tiers?

The tiers let one setup serve many purposes. The warn tier can trigger alerts, because anything at that level is really bad. The info tier is a daily review list. The debug and trace tiers are gentler limits for hunting slightly slow operations when you have time or when the cluster is quiet. Later, when you ship logs to a central place, you can filter by level to keep the noisy tiers out of your alerting.

Thresholds apply to time, not to importance

A slow log line tells you that something was slow, not that it was important. A monthly finance report that legitimately takes forty seconds will appear in the log every month, and it is not a problem. Good teams learn the usual suspects and mark them as expected, so their attention goes to the surprises.

Sample values from the official documentation

The Elasticsearch documentation shows a set of example limits that many teams use as a starting point. For the query phase, warn at ten seconds, info at five seconds, debug at two seconds, and trace at half a second. For the fetch phase, warn at one second, info at eight hundred milliseconds, debug at five hundred milliseconds, and trace at two hundred milliseconds. For indexing, the same shape as the query limits is used. These are examples, not rules. Your own limits should come from your own expectations.

i
How to choose your first numbers

Start from your service goals. If you promise users that searches finish within one second, set the warn limit slightly above that promise, and pick lower tiers below it. Then watch the volume for a day. If the log is empty, lower the limits. If it is flooded, raise them or fix the biggest offender.

7Configuring the Slow Log

The slow log is controlled by index settings, so you can tune it per index and change it on a live cluster without a restart.

Search

Query phase limits

Settings that start with index.search.slowlog.threshold.query and end with warn, info, debug, or trace set the limits for the query phase.

Search

Fetch phase limits

Settings that start with index.search.slowlog.threshold.fetch and end with a level name set the limits for the fetch phase.

Indexing

Index limits

Settings that start with index.indexing.slowlog.threshold.index and end with a level name set the limits for document writes.

Indexing

Source options

index.indexing.slowlog.source controls how many characters of the document are logged, and index.indexing.slowlog.reformat controls whether it is squeezed onto one line.

Index settings are dynamic

All of these are dynamic settings, which means you can change them while the index is in use. You change them through the update index settings operation, and the new values take effect right away. To go back to the default, you set the value to null, or to minus one for a threshold you want disabled.

Choosing which indices to cover

Settings belong to individual indices, but you can apply them to many at once by using an index name pattern with a wildcard. For a family of daily indices, you can set limits once for all current ones. For future ones, the limits must live in an index template, which is a saved recipe that Elasticsearch applies to each new matching index when it is created. A template does not change indices that already exist, so a complete setup needs both: an update for current indices and a template for new ones.

Everyday Analogy

A school principal changes the rule “late after 8:30” on the notice board. Students already in the building follow the new rule immediately. But the printed handbook for next year’s new students still says the old time until it is reprinted. The update operation is the notice board, and the index template is the handbook.

The indexing source settings

An indexing slow log line can include a copy of the document that was slow. This helps you recognize the culprit, but documents can be big and can contain private information. The source setting lets you choose. By default, only the first thousand characters are included. You can turn it on fully, cut it shorter, or switch it off entirely with false or zero. The reformat setting, which is on by default, squeezes the copy onto a single line so that one log entry is one text line. Turning it off keeps the original layout, which may spread one entry across several lines and complicate log processing.

Including who asked

Newer versions can add information about the authenticated user to slow log lines through an include-user setting on each of the two logs. It is off by default. When it is on, you can tell which user or key sent a slow request, which is very helpful in shared clusters where many teams send traffic.

Log files and the logging configuration

Where the lines end up is decided by the node’s logging configuration, not by index settings. Elasticsearch uses a logging library named log4j2, and its configuration file defines two named loggers for the slow logs: one for searches and one for indexing. Each is attached to its own rolling file, which means the file is closed and a new one is started when it becomes too large or too old. Administrators can change these details, for example to write into a different folder or keep more history, by editing the logging configuration on every node and restarting.

What you want to changeWhere you change itNeeds a restart?
Thresholds for an existing indexIndex settings, through the update operationNo
Thresholds for future indicesIndex templateNo
Source length and reformatIndex settingsNo
Log file location, rotation, and retentionThe logging configuration file on each nodeYes
!
Version note

Setting names, extra options, and file formats have grown over the years. The names above are the long-standing core ones. Before relying on any newer option, confirm it in the documentation for the version you run.

8Anatomy of a Slow Log Line

Each line packs many facts into a small space. Knowing what each field means lets you read a line like a sentence.

Modern Elasticsearch writes slow log lines as JSON. JSON is a simple way to write labeled information, where every fact has a name and a value, so machines can read it easily. A line also has the usual log fields, such as the time it was written, the level, the name of the node, and the name of the cluster. On top of these, the slow log adds fields that begin with elasticsearch.slowlog.

Fields in a search slow log line

Field ideaWhat it tells youHow to use it
Message with index and shardWhich index and which shard number was slowCount how often the same shard appears to spot a hot shard
Took, as text and as millisecondsHow long the shard spent on this phaseSort and chart the milliseconds value to find the worst cases
Total hitsHow many documents matched on this shardHuge numbers suggest very broad queries
Search typeThe style of search used, such as the usual query then fetchCheck for unusual search styles
Total shardsHow many shards the whole search touchedMany shards per search can explain overall slowness
SourceThe search body that was sentGroup by shape to find the repeating offenders
Stats groupsOptional labels the client attached to the requestTag features or teams so their traffic is easy to filter
Opaque idAn identifier the client attached with a special headerTrace one slow line back to the application call that made it

Fields in an indexing slow log line

Field ideaWhat it tells youHow to use it
Message with index and shardWhich index and shard did the writeCheck whether one shard is always slow, hinting at a struggling node
Took, as text and as millisecondsHow long the shard spent on that documentChart it over time to spot spikes
Document idThe id of the document that was writtenFind the exact document and inspect its size and shape
RoutingThe routing value used, if anyUneven routing can pile work on one shard
SourceThe first part of the document, if enabledLook for giant fields or thousands of tiny ones
Everyday Analogy

A slow log line is like a parking ticket. It says where it happened (index and shard), how long the car stayed (took), what kind of car it was (the source), and sometimes who parked it (the user or the opaque id). The ticket does not tell you why the driver parked there, but it gives you every fact you need to go and ask.

Reading a line step by step

1

Read the level and the time

The level tells you which tier of slowness was reached. The time tells you when. Line it up with your dashboards to see what else was happening then.

2

Find the index and the shard

These come from the message. They show where the work happened and hint at which node to inspect.

3

Check the took value

Use the milliseconds field for sorting. Remember that it is per shard and per phase.

4

Study the source

Look at the shape of the query or the document. Are there wildcards, scripts, huge lists, or deep paging?

5

Use the identifiers

If the client sent an opaque id or a user identity was recorded, connect the line to an application feature or a person to ask.

i
Make lines traceable

Ask your application developers to attach an opaque id header to every search, using a value such as the feature name plus a request number. It costs nothing and turns an anonymous slow line into a named suspect.

9Where the Logs Live and How to Collect Them

Slow log lines are written on the node where the shard lives. In a real cluster you need a plan to gather them into one place.

On each node, Elasticsearch has a logs folder whose location is set by its configuration. Inside, you will find the normal cluster log and, once slow logging produces something, the slow log files: one for searches and one for indexing, named after the cluster. Modern versions write them as JSON files, while older versions also wrote plain text versions. Files are rotated, meaning that when they get large or old, they are closed, renamed, and possibly compressed, and a new file begins.

The problem of many nodes

Because each shard copy writes to its own node’s file, the evidence for a single slow search may be spread across several machines. Logging into each node and searching files by hand does not scale. A cluster with thirty data nodes would need thirty separate visits. The answer is to ship the logs to a central place.

Everyday Analogy

Imagine a chain of thirty bakeries, and each shop manager keeps a paper notebook of complaints. The owner cannot visit thirty shops every morning. So each manager sends a photo of the notebook page to a shared folder at closing time. Now the owner reads one folder and sees which shop, which product, and which hour has the most complaints. Log shipping is that shared folder.

flowchart LR
    A["Data node 1: slow log files"] --> D["Log shipper such as Filebeat or Elastic Agent"]
    B["Data node 2: slow log files"] --> D
    C["Data node 3: slow log files"] --> D
    D --> E["Monitoring cluster or log store"]
    E --> F["Dashboards and searches in Kibana"]
    E --> G["Alert rules"]
Figure 5: Slow log files on every node are picked up by a shipper and stored centrally, where they can be searched, charted, and alerted on.

Common ways to collect

  • Filebeat with its Elasticsearch module. Filebeat is a light program that reads log files and sends the lines onward. Its Elasticsearch module knows about the slow log files and parses the fields for you.
  • Elastic Agent with the Elasticsearch integration. The newer, unified collector offers the same idea with central management.
  • Managed cloud logging. On managed Elasticsearch offerings, slow logs can often be delivered through the provider’s log features once they are enabled in the settings. The exact steps depend on the provider.
  • Any general log platform. Because the files are structured JSON, most log platforms can ingest them with a small amount of setup.

Keep the monitoring separate

Many teams send slow logs to a separate monitoring cluster instead of the production cluster being watched. If the production cluster is struggling, you still want to read the evidence. A separate destination also avoids the odd loop in which the act of storing slow logs creates more load on the very cluster that is slow.

Retention

Decide how long to keep the lines. A few weeks is common for detailed review. Some teams keep summaries longer, such as counts per query shape per day, because trends over months help with capacity planning. Retention should match your needs, and privacy rules may set an upper limit, as discussed in Chapter 17.

10A Step-by-Step Investigation Workflow

Reading logs without a plan is tiring. This simple loop turns raw lines into fixes and proves that the fixes worked.

1

Set sensible thresholds

Start with limits based on your service goals. Apply them to the indices that matter most, and add them to index templates for future indices.

2

Let it collect

Wait for a normal business cycle, often one day or one week. A short window may miss a weekly report or a monthly job.

3

Group the lines

Group by index, by query shape, by time of day, and by opaque id or user. A pattern usually appears in minutes when the lines are grouped rather than read one by one.

4

Rank the offenders

Rank groups by total time spent, which is the count multiplied by the average time. A moderately slow query that runs a million times costs more than a very slow one that runs twice.

5

Reproduce and profile

Take the source from a typical line, run it against a test copy or a quiet time, and use the profile option to see which part of the query is expensive.

6

Fix the cause

Change the query, the mapping, the shard layout, or the hardware, depending on what the evidence says. Chapters 11 and 12 list common causes.

7

Verify and repeat

Compare the slow log volume and dashboards before and after. Then look at the next offender on the list.

flowchart TD
    A["Set thresholds"] --> B["Collect lines for a full business cycle"]
    B --> C["Group by index, query shape, time, and caller"]
    C --> D["Rank by total time spent"]
    D --> E["Reproduce with the profile option"]
    E --> F["Fix the query, mapping, or layout"]
    F --> G["Compare slow log volume before and after"]
    G --> C
Figure 6: The investigation loop. Each pass removes the biggest offender and reveals the next one.

Rank by total cost, not by worst case

New readers of the slow log often chase the single slowest line. That feels natural, but it can mislead. A query that took 40 seconds once might have hit a garbage collection pause. A query that took 1.2 seconds but appeared 50,000 times today is the real drain. The best measure is usually frequency multiplied by time, which tells you how much of the cluster’s day each shape consumed.

Everyday Analogy

A family looks at their electricity bill. The oven uses a lot of power, but only for an hour on Sundays. The old refrigerator uses a moderate amount, but it runs all day and every day. Over the month, the refrigerator costs more. The same is true for queries: the quiet, frequent, slightly slow ones often cost more than the dramatic, rare ones.

Capture a baseline first

Before making changes, save a copy of the counts and the average times of the top groups. Without a baseline, you cannot show that a fix worked, and you cannot notice that a later release made things worse.

i
Investigating during an incident

In an emergency, you can lower the thresholds on the affected index, even down to a few hundred milliseconds, to gather more evidence quickly. Note the change so you can raise it again once the incident is over, because low limits generate a lot of lines.

11Common Causes of Slow Searches

After a few weeks of reading slow logs, the same handful of culprits appear again and again. Here are the usual suspects and how to recognize them.

Query shape

Leading wildcards and regular expressions

Searching for text that begins with an unknown part, or using complicated patterns, forces Elasticsearch to check a huge number of terms. Look for stars at the start of search terms in the source.

Query shape

Scripts in queries or sorting

A script runs once for each candidate document. On millions of documents that adds up quickly. Look for script sections in the source.

Paging

Deep pagination

Asking for page five hundred with a large offset makes each shard build and discard a huge list. Look for a large from value in the source.

Aggregations

Huge or high-cardinality groupings

Grouping by a field with millions of different values, or nesting several groupings, creates enormous partial results. Look for large size values in aggregation parts.

Fetch phase

Large documents or many results

A slow fetch phase often means big stored documents, or a request for hundreds of results with all their fields. Trim the fields and the count.

Layout

Too many shards

A search over hundreds of tiny shards pays overhead on each one. Total shards in the line will be large. Consider fewer, larger shards.

Mapping

Wrong field types

Searching numbers stored as text, or using expensive text matching for exact values, wastes time. Review the mapping against actual use.

Environment

Cold caches, memory pressure, or busy disks

Even good queries look slow after a restart or when the machine is starved. Check whether slow lines cluster around specific nodes or times.

Filters versus scoring

Many searches mix two ideas: matching documents, and ranking them by relevance. When you only need a yes-or-no test, such as “status is published,” it is cheaper to place that test in a filter, because filters skip the scoring step and can be reused from a cache. If the slow log shows large queries where most conditions are yes-or-no tests inside scored parts, moving them into filters is often an easy win.

The chatty client

Sometimes no single query is slow, but a client sends the same medium-slow query many times per second, perhaps because a page refreshes too often. The slow log shows this as a long list of near-identical lines. The fix lives in the application: fewer refreshes, shared results, or a cache in front of the cluster.

The hot shard

If most slow lines mention the same shard or the same node, then the problem may be that shard’s data, its node’s hardware, or its uneven share of the traffic. Compare it with its siblings. A shard that is much larger than its peers, or a node with a slower disk, often explains the whole pattern.

i
Look at fetch and query separately

A slow query phase points to matching, scoring, or aggregation work. A slow fetch phase points to document size and result count. Treating them separately avoids fixing the wrong half.

12Common Causes of Slow Indexing

Writes are slowed by a different set of problems. The indexing slow log helps you separate a bad document from a bad disk.

Document

Very large documents

Huge text fields or embedded blobs take longer to analyze and store. Look at the source and the size of slow documents.

Mapping

Too many fields

Documents with thousands of distinct field names, often caused by using data values as field names, slow down mapping updates and indexing. This is known as mapping explosion.

Mapping

Dynamic mapping updates

When a new field appears, the cluster must agree on the change, which takes time. A stream of new field names causes repeated slow writes.

Disk

Slow or saturated storage

If slow lines cluster on one node, its disk may be the bottleneck. Compare disk throughput and waiting time across nodes.

Background work

Merges and refreshes

Heavy background merging competes for the same disk and CPU. Bursts of slow writes that line up with merge activity suggest this.

Settings

Waiting for refresh

Writes that ask to wait until the data is visible take as long as the next refresh. This can look like slowness even when the shard is healthy.

Layout

Uneven routing or hot shards

If most writes go to one shard because of a routing choice, that shard is overloaded. The slow lines will all name it.

Memory

Garbage collection pauses

Long pauses of the Java runtime freeze everything on a node, so slow writes and slow searches show up together at the same moments.

Do not forget what is not measured

If your data passes through an ingest pipeline before it is stored, the time spent there is not part of the indexing slow log. A team can spend days tuning the shard layout while the real delay sits in a pipeline processor. Check the pipeline statistics as a separate step. Similarly, time spent by your own application preparing documents or waiting on the network is invisible here.

Bulk sizes and concurrency

The way clients send data also matters. Very small bulk requests waste trips. Very large ones hold memory and can cause pauses and rejections. There is no universal best size. Teams find it by measuring: try a range, watch throughput and slow lines, and choose a value on the plateau. Sending from too many parallel clients can overload the write queues, so control concurrency as well.

Everyday Analogy

Loading boxes onto a truck works best with a sensible carrying size. If workers carry one small item at a time, the walk back and forth dominates. If they try to carry huge crates, they slow down and risk dropping them. The best rhythm is in the middle. The indexing slow log tells you when the rhythm breaks.

!
Replicas do work too

Every replica repeats the write, so a slow replica node can appear in the log while the primary looks fine. When comparing lines, note which copy wrote them. Slowness on replicas can also make the client wait, because the write is confirmed only after the copies have done their part.

13Performance, Overhead, and Scalability

The slow log itself costs very little when its limits are sensible. It becomes costly only when the limits are so low that it writes far too much.

The cost of checking

Every search phase and every document write already measures its own duration for normal statistics. The slow log adds a comparison against a few numbers, which is a trivial amount of work. The real cost appears only when a line is written: building the text, copying the query or document source, and writing to disk. A cluster that writes a handful of lines per minute will never notice. A cluster that writes thousands of lines per second may spend measurable CPU and disk time on logging alone.

How volume grows

The volume of slow log data depends on three things: how many operations you run, how many of them cross the limits, and how big each line is. Line size is often dominated by the source. A search body with a long list of filters, or a document with big text fields, can make each line several kilobytes. Multiply by the number of lines per day, and you can estimate disk use easily. Chapter 19 shows a worked example.

Shards multiply the lines

Because entries are written per shard, an index with more shards can produce more lines for the same search. A slow search across 40 shards, where 25 of them cross the limit, writes 25 lines. This is a good reason to keep shard counts reasonable, and also a reason to choose limits with the shard count in mind. A limit that gives a tidy log on a small index can flood the log on a large one.

Tiny
Cost of comparing a time against thresholds
Moderate
Cost of writing each line, mostly the copy of the source
Large
Cost of a zero-millisecond threshold left on in production
Everyday Analogy

A teacher who marks only the late homework in a notebook spends almost no time on it. A teacher who writes a full paragraph for every single homework, even the on-time ones, would spend more time writing notes than teaching. Setting a threshold of zero turns your slow log into that second teacher.

Protecting the disks

Log rotation limits the size of individual files and, when configured, the total history. Still, a sudden flood can fill a disk faster than rotation can react. Make sure the log folder has enough space, set alerts on disk usage, and consider placing logs on a different volume than your index data so that a log flood cannot starve the shards.

Scaling with the cluster

As the cluster grows, the slow log scales naturally, because each node writes only about its own shards. There is no central bottleneck in Elasticsearch itself. The pressure moves to the collection pipeline and the storage where you keep the lines. Plan those to handle the busiest day, not the average.

i
Measure the effect of the change

After adding or lowering thresholds, watch CPU, disk write rates, and the count of lines per minute for a while. If nothing moves except the log volume, you have chosen well.

14Advantages, Disadvantages, and Trade-offs

No tool is perfect. Here is an honest scorecard so you can decide when to lean on the slow log and when to look elsewhere.

Advantages

  • Built in, so there is nothing extra to install on the cluster.
  • Finds slow requests on its own, without knowing them in advance.
  • Configurable per index, with four tiers of limits.
  • Changes take effect at once, with no restart for thresholds.
  • Very low overhead when limits are sensible.
  • Writes structured lines that machines can group and chart.
  • Covers both searches and document writes.
  • Gives evidence that non-experts can understand and act on.

Disadvantages

  • Off by default, so many clusters have no history when trouble starts.
  • Measures shard-level time only, so queueing, network, and merging delays are invisible.
  • Writes only after an operation finishes, so it cannot show a stuck request.
  • Lines are scattered across nodes and need collecting.
  • Logged sources may contain sensitive information.
  • Low limits can create a flood of lines and fill disks.
  • Does not explain why something was slow.
  • Templates do not change existing indices, which leads to gaps in coverage.

The central trade-off: detail against noise

Lower limits capture more and give finer detail, but they also produce more lines and more cost. Higher limits give a quiet log that shows only the disasters. The best setting is the one where the log is short enough to read regularly but sensitive enough to reveal trends. That balance moves over time as your cluster and your goals change.

The second trade-off: insight against privacy

Including the full query or document source makes lines easy to understand, but it also copies possibly sensitive data into log files. Shortening or removing the source protects privacy but makes each line harder to interpret. Many teams keep the source for searches, which usually hold filters rather than personal data, and cut or remove it for indexing.

The third trade-off: local files against central collection

Leaving the files on each node is simple, but hard to use. Shipping them centrally is more work to build, but far more powerful. The added effort pays back the first time you need to answer “what was slow last Tuesday across the whole cluster?”

When the slow log is the wrong tool

If the problem is a request stuck right now, use the tasks operations. If the problem is one query you already know about, use the profile option. If the problem is queueing and rejections, look at thread pool statistics. If the problem is that the coordinating node is overloaded merging results, look at that node’s CPU and memory. The slow log is best for the question, “over the last days, which shard-level work was slower than expected?”

15Design Patterns for Effective Slow Logging

Good slow logging rarely happens by accident. These six habits make the log easy to collect, easy to read, and easy to act on.

Pattern 1

Tiered thresholds

Use all four tiers with a sensible spread. Warn is for genuine trouble and alerts, info for the daily review, and debug and trace for deeper hunts.

Pattern 2

Limits per index family

Different indices have different expectations. A product search index might need 500 milliseconds, while an archive index for analysts might accept 30 seconds. Set limits per family through templates.

Pattern 3

Tag every request

Have clients send an opaque id and, where possible, stats group labels. Every line then points to a feature or a team.

Pattern 4

Central collection

Ship slow logs from every node to one searchable place, preferably a separate monitoring cluster, with dashboards for count, level, index, and query shape.

Pattern 5

Temporary deep dives

During an incident or an experiment, lower the limits on one index for a short time, gather evidence, and then restore the normal values. Record the change so it is not forgotten.

Pattern 6

Regular review ritual

Schedule a weekly look at the top offenders by total time spent. Turn each into a ticket with an owner. Track the count over time as a health measure.

Pattern 2 in action

Suppose a company has three families of indices: customer-facing product search, internal analytics, and audit archives. The customer-facing family gets tight limits, with warn at one second and info at 500 milliseconds. The analytics family gets warn at ten seconds. The archive family gets warn at sixty seconds, because slow queries there are normal. Each family lives in its own template. The result is a log whose lines almost always deserve a look.

Pattern 4 in action

A team ships slow logs from all nodes to a small monitoring cluster. They build a dashboard with four charts: lines per hour by level, top indices by slow lines, top query shapes by total time, and top callers by opaque id. On Monday mornings, the on-call engineer opens the dashboard and knows within five minutes what deserves attention this week.

A pattern for a healthy culture

Make slow log findings visible and blameless. When the dashboard shows that a new feature made search slower, share the finding as information for improvement, not as a complaint. Teams that see the slow log as a friendly mirror fix problems faster than teams that see it as a source of blame.

i
Pair with the release process

Look at the slow log count and top shapes before and after every release that changes searches or mappings. A quick before-and-after comparison catches regressions on the same day, when the change is still fresh in everyone’s mind.

16Anti-Patterns and Common Mistakes

These are the traps that make the slow log useless, noisy, or risky. Each one is common in real projects and easy to avoid once you know it.

ANTI-PATTERN 01Avoid
What people do

They set the threshold to zero milliseconds on a production index and forget about it.

Why it hurts

Every operation is logged. Disks fill, CPU goes up, and the interesting lines are buried in a mountain of ordinary ones. Log shipping falls behind.

Better approach

Use zero only for a short, planned experiment on a small index, and set a reminder to restore normal limits.

ANTI-PATTERN 02Avoid
What people do

They treat the number in a line as the total time the user waited.

Why it hurts

The slow log measures only the shard’s own work. Queueing, network, merging, and client time are outside it. Teams then either miss real problems or blame the wrong component.

Better approach

Compare the slow log with client-side timings and cluster statistics, and remember that the number is per shard and per phase.

ANTI-PATTERN 03Avoid
What people do

They read the slow log from one node only and conclude that the cluster is healthy.

Why it hurts

Each shard writes on its own node. The slow work may be happening on another machine entirely.

Better approach

Collect the logs from every node into one place, and always search across all of them.

ANTI-PATTERN 04Avoid
What people do

They put thresholds in an index template and assume all indices are covered.

Why it hurts

A template only affects indices created after it is saved. Older indices stay silent, and the gap goes unnoticed until an incident.

Better approach

Apply the limits to existing indices through the settings update, and add them to the template for future ones.

ANTI-PATTERN 05Avoid
What people do

They log full document sources for indexing and keep the files for a long time with wide access.

Why it hurts

Personal or confidential data spreads into log files that are not protected like the main data. This can break privacy rules and expose secrets.

Better approach

Shorten or switch off the source, restrict who can read the logs, and set a retention period.

ANTI-PATTERN 06Avoid
What people do

They use the slow log as an outage alarm and expect it to warn them about a hung cluster.

Why it hurts

Lines are written only after operations end. During a real freeze, nothing finishes, so nothing is written. The slow log stays quiet exactly when you need help.

Better approach

Use health checks, latency monitoring from the client side, and queue and rejection metrics for outage alarms, and use the slow log for finding patterns.

Other frequent mistakes

  • Choosing limits once and never revisiting them as the data and traffic grow.
  • Chasing the single slowest line instead of the biggest total cost.
  • Fixing the query when the real delay was in an ingest pipeline or the network.
  • Forgetting to reset a temporary low threshold after an incident.
  • Leaving out the fetch phase limits and missing slowness caused by large documents.

17Security and Privacy Considerations

The slow log copies your data into new places. Treat those copies with the same care as the data itself.

A search slow log line contains the body of the search, which may include names, email addresses, account numbers, or other values that users typed into search boxes. An indexing slow log line can contain the beginning of the document, which may hold even more. Because these lines are written into ordinary files and then shipped to other systems, they can quietly become a second copy of sensitive data that lives outside your usual protections.

Everyday Analogy

A bank locks its vault at night, but a manager keeps a notebook on the desk listing every unusual transaction with names and amounts. If the notebook is left open, the vault lock does not matter. Slow log files are that notebook. They deserve a lock too.

Practical protections

  • Limit the source. Use the source setting to log fewer characters or none for indexing. For searches, review whether queries can carry personal values, and consider designing the application so that identifiers, not raw personal data, appear in queries.
  • Restrict access. Only people who need the logs should read them. Apply file permissions on the nodes and role-based access in the central store.
  • Protect the shipping path. Send logs over encrypted connections and authenticate the collectors.
  • Set retention. Delete old lines after the review period ends. Shorter retention means smaller exposure.
  • Mind the user fields. Newer versions can record which user made a request. This is very useful for accountability, but it is also personal data in some rules, so decide on purpose whether to turn it on.
  • Watch for secrets. If queries or documents can carry tokens or passwords, they can land in the log. Find and remove such practices at the source.
!
Compliance reminder

If your organization follows privacy regulations that give people the right to have their data deleted, remember that slow logs may contain copies. Keep retention short, and confirm your exact obligations with your security and legal teams.

Operational security

Restrict who may change slow log settings. Lowering thresholds can drive a flood of lines, and raising them can hide evidence. Treat setting changes like any other production change: request, review, apply, and record. Also remember that changing log file locations and rotation involves the node’s configuration files, which should be under version control.

Slow logs as a security signal

Interesting side effect: abnormal patterns in the slow log, such as a burst of very heavy queries from an unusual user, can hint at misuse or an attack that tries to overload the cluster. The slow log is not a security tool, but it can be one more source of clues, especially when the user information is recorded.

18Monitoring and Alerting on the Slow Log

Once the lines are collected, turn them into a few clear charts and a small number of useful alerts.

Raw lines are for investigation. For day-to-day awareness, you need summaries. A short list of charts covers most needs, and each one answers a simple question.

Chart or metricQuestion it answersWhat to watch for
Lines per hour by levelIs slowness rising, falling, or steady?Sudden jumps, especially at the warn level
Lines by indexWhich data is causing the trouble?One index dominating the list
Lines by shard and nodeIs it a hot shard or a weak machine?The same node or shard appearing again and again
Top query shapes by total timeWhich requests cost the most overall?New shapes appearing after a release
Top callers by opaque id or userWho or what sends the heavy requests?A single feature or team standing out
Slow lines against total requestsWhat share of traffic is slow?A rising share, even if the raw count is steady
Indexing lines by hourAre writes struggling at certain times?Alignment with bulk jobs or merges

Alerting with care

Alerts should be rare and meaningful. A good starting set has three rules. First, alert when the count of warn lines in a ten-minute window is above a normal ceiling. Second, alert when the share of slow operations compared with all operations rises well above its usual level. Third, alert when a new query shape appears with a high count within a short time. Avoid alerting on single lines, because a single slow request is normal and will teach people to ignore the alerts.

Everyday Analogy

A smoke alarm that rings whenever someone makes toast is soon taken off the ceiling. A good alarm rings when there is a real fire. Alerts on the slow log should work the same way: quiet on ordinary slow moments, loud on real changes in behavior.

Combining signals

The best alerts combine the slow log with other signals. A rise in slow lines together with rising CPU and rising search thread pool queues is a strong sign of overload. A rise in slow lines with flat CPU may point to a specific query or a slow disk. Comparing signals helps you choose the right first action.

Linking to a runbook

Each alert should link to a short runbook, a page that says what the alert means, how to check the top offenders, and who to call. The first time an alert fires at night, that page saves many minutes and much confusion.

i
Keep the dashboard simple

Five or six charts that people actually open are worth more than thirty that nobody understands. Start small, and add a chart only when a real question demands it.

19Sizing and Capacity Planning for Slow Log Data

You can estimate how much space and traffic the slow log will create before you switch it on, using simple arithmetic.

Three numbers decide the volume: how many lines per day, how large each line is, and how many days you keep them. Multiply them together, and add some headroom for growth and for busy days.

1

Estimate operations per day

Look at existing statistics for the number of searches and document writes. Remember that searches count per shard, so multiply by the average number of shards touched.

2

Guess the slow share

Start with an assumption, such as one percent of shard-level operations crossing the lowest limit. Adjust after a day of real data.

3

Estimate line size

Take a sample line and measure it. A simple search line may be a few hundred bytes. A line with a large query body or document source may be several kilobytes.

4

Multiply and add headroom

Lines per day times line size gives daily volume. Add thirty percent or more for peaks and growth, then multiply by the retention days.

5

Check the pipeline capacity

Confirm that shippers, network, and the central store can absorb the busiest hour, not just the daily average.

A worked example

Sizing for a mid-sized search platform

Imagine a platform that handles 20 million searches per day, each touching an average of 8 shards, so 160 million shard-level query phases. If one percent crosses the lowest limit, that is 1.6 million lines per day. At an average of 1.5 kilobytes per line, the daily volume is about 2.4 gigabytes. Over 14 days, that is roughly 34 gigabytes, and with 30 percent headroom, about 44 gigabytes. That is quite manageable, but if the limit were lowered so that ten percent of operations crossed it, the volume would be ten times larger, at 440 gigabytes for two weeks. The example is invented to show the arithmetic, and your own numbers will differ.

Ways to reduce the volume without losing insight

  • Raise the lowest tier a little, so that trace and debug lines are less common.
  • Shorten or remove the logged source when the query shape is already known from other data.
  • Apply low limits only to the indices you care about, and higher limits to bulk archives.
  • Store detailed lines for a short time and keep only daily summaries for long-term trends.
  • Reduce the shard count where it is unnecessarily high, because each shard multiplies the lines.
!
Do not forget bursts

A bad deployment or a sudden traffic spike can multiply the volume within minutes. Size the pipeline for the worst hour you can imagine, and set alerts on log disk usage as an early warning.

20Failure Scenarios and Gotchas

The slow log can fail in quiet ways. Knowing them in advance keeps surprises small.

Logs vanish when a node is replaced

If a node is replaced or its disk is wiped, its local log files go with it. Any evidence not yet shipped is lost. Central shipping with a short delay is the protection. Also, in containerized setups, remember to place the log folder on a volume that survives restarts, or ship logs out directly.

Shard moves scatter the evidence

Elasticsearch may move shards between nodes for balance or recovery. A slow shard’s history may therefore be split across the old and the new node. Central collection makes this invisible, because you search by index and shard rather than by machine.

The log disk fills up

A flood of lines can fill the disk that holds the logs. If that disk is shared with data, the node can run into disk watermarks and stop accepting writes. Use a separate volume where possible, watch usage, and keep rotation limits sensible.

Shipping falls behind

If the shipper or the central store cannot keep up, lines queue on the nodes or are dropped. You then see gaps in charts exactly at the busiest times. Monitor the shipper’s own health and delay.

Time zones and clocks

Lines carry timestamps written by each node. If node clocks drift, lines from different nodes will not line up correctly, making a single incident look scattered. Keep clocks synchronized with a time service, and prefer a single time zone, usually UTC, in logs and dashboards.

Settings that quietly did not apply

A typing error in a setting name, a wrong index pattern, or a template that was saved after the index was created can leave an index without limits. Always check the live settings of an index after changing them. A simple habit is to read back the settings and confirm that the values you expect are present.

Everyday Analogy

A night watchman writes down every strange noise in a notebook. If the notebook gets soaked in a storm, if the watchman is on a different floor than the noise, or if his watch runs ten minutes fast, the notes become unreliable. The slow log has the same weaknesses, so a good design protects the notebook, covers every floor, and sets every watch to the same time.

Design for a quiet log

Finally, remember that an empty log is not always good news. It may mean that thresholds are too high, that settings are missing, or that the delay is outside the shard. Confirm your setup by generating a known slow operation in a test index, and check that it shows up. That one test builds trust in everything else.

i
A quick self-test

On a test index, set a very low limit, run a normal search, and confirm that a line appears in the central store within a minute. Then restore the normal limit. This proves the full path, from the shard to the dashboard.

21Real-World Scenarios

Here are four common situations, with rough numbers, showing the slow log at work. The companies are imaginary, but the patterns are the ones teams meet every day.

Scenario 1: The evening slowdown at an online store

The imaginary store TrailMart hears that search feels slow on weekday evenings. The search slow log, set to one second, shows 4,000 lines between six and nine o’clock. Grouping by query shape reveals that 70 percent come from a sort by a computed “popularity score” using a script. The team stores the score as a normal field at indexing time, and the slow lines fall by 90 percent the next day.

Scenario 2: The nightly load that got slower

A data team at the imaginary media company PressLine runs a nightly load that used to finish in two hours and now takes four. The indexing slow log shows many lines from a single shard on one node. Checking that node reveals a failing disk with poor throughput. After moving the shard and replacing the disk, the load returns to two hours. Without the log, the team might have spent days tuning batch sizes.

Scenario 3: The dashboard that nobody owned

A shared analytics cluster at the imaginary firm LedgerLine has dozens of teams. The slow log with user information turned on shows that one service account causes most of the heavy aggregations, every ten minutes, around the clock. The owner turns out to be an old report that nobody reads anymore. Turning it off saves an entire node’s worth of capacity.

Scenario 4: The mapping explosion

A logging platform at the imaginary company SignalNest sees slow indexing lines for documents with tens of thousands of distinct field names, because a service uses user identifiers as field names. Slow writes and slow cluster updates follow. After the developers change the format to use a field for the identifier value instead, indexing time per document drops from hundreds of milliseconds to a few.

A worked example with numbers

1

Set the scene

An index has 10 shards. A team sets the query phase warn limit to 2 seconds and info to 1 second. A daily report search normally takes 300 ms per shard.

2

A normal day

All shards finish in about 300 ms. The log has no lines for the report.

3

The data grows

After a quarter, one shard holds twice the data of the others. Its time rises to 1.3 seconds, which crosses the info limit. One info line appears each day for that shard.

4

A pattern emerges

The weekly review shows 30 info lines for the same shard over a month and none for the others. This points at uneven shard sizes, not at the query.

5

The fix

The team reviews routing and finds that a small number of very large customers land on that shard. They change the routing approach so the load is spread more evenly. The lines disappear.

22Troubleshooting: My Slow Log Is Empty

When you expect lines and see none, work through this checklist from the most common cause to the least common.

1

Check that thresholds are set

The default is minus one, which means never log. Read the live settings of the index and confirm that at least one threshold has a real time value.

2

Check the right index

Make sure the settings apply to the index that receives the traffic. A pattern typo, or a template saved after the index was created, are common causes.

3

Check the right phase

Query and fetch have separate limits. A search that is slow because of a huge fetch will not show in a query limit, and the other way around.

4

Check the time values

Confirm that the thresholds are not higher than the slowest operations. If your slowest search takes 800 ms, a one-second limit will never fire.

5

Look on every node

Lines are written on the node hosting the shard. Check the logs on all nodes, or the central store, not only the node you connected to.

6

Check the log configuration

Confirm the logging configuration still defines the slow log loggers and files, and that the logs folder is the one you are reading.

7

Check the shipping path

If files contain lines but the dashboard is empty, look at the shipper’s status, its file paths, and any parsing errors.

8

Look outside the shard

If everything above is fine, the delay may be in queues, the network, the coordinating node, an ingest pipeline, or the client. Check thread pool statistics and client-side timings.

i
A clean test

Set a very low limit on a small test index, run one search against it, and check the logs. If a line appears, the mechanism works, and the problem is in the settings or the target index. If not, the issue is in the logging setup or the collection path.

23Frequently Asked Questions

Q1Is the slow log turned on by default?
No. All thresholds start at minus one, which means never log. You have to set at least one threshold on the indices you care about.
Q2Do I need to restart Elasticsearch to change thresholds?
No. The thresholds are dynamic index settings and take effect immediately. Changes to log file locations or rotation live in the logging configuration and do need a restart.
Q3Does the time in a line equal what my user waited?
No. It is the time one shard spent on one phase of a search, or on one document write. Queueing, network time, and merging on the coordinating node are not included.
Q4Why do I see several lines for one search?
Each shard is measured separately and writes its own line if it was slow. A search across many shards can therefore produce many lines.
Q5What is the difference between warn, info, debug, and trace?
They are four tiers of slowness, each with its own time limit. The most serious tier whose limit is reached decides the level of the line. Usually warn has the largest limit and trace the smallest.
Q6Does the slow log slow down my cluster?
Not noticeably when the limits are sensible. Checking a time against a limit is very cheap. The cost appears when a very low limit makes the cluster write huge numbers of lines.
Q7Can the slow log show a search that is stuck right now?
No. Lines are written after operations finish. Use the tasks operations to see what is running at this moment.
Q8Does the indexing slow log include ingest pipeline time?
No. Pipelines run before the shard starts its own work, so they are outside the measurement. Check pipeline statistics separately.
Q9Can the slow log leak private data?
It can, because it copies search bodies and, optionally, the start of documents into log files. Limit or switch off the source, restrict access to the logs, and set a retention period.
Q10How do I cover new indices automatically?
Put the settings in an index template so that each new matching index gets them at creation. Also apply them to existing indices, because templates do not change indices that already exist.
Q11Should I use a threshold of zero to see everything?
Only briefly, on a small index, for an experiment. Zero logs every operation and can flood your disks and pipeline if left on.
Q12What should I do after I find a slow query in the log?
Reproduce it on a safe copy, use the profile option to see which part is expensive, fix the query, mapping, or layout, and then compare slow log volume before and after to confirm the improvement.

24Summary and Key Takeaways

The slow log is a simple idea with a big payoff when you actually read it. Here is everything to remember.

Key Takeaways

  • What it is: two per-index, threshold-based diaries, one for slow searches and one for slow document writes, off until you set limits.
  • What it measures: the time a single shard spent on one search phase or one document write, not the total wait seen by the client.
  • How levels work: four tiers named warn, info, debug, and trace, where the most serious tier reached decides the label of the line.
  • How to configure it: use dynamic index settings for limits, templates for future indices, and the logging configuration for file details.
  • How to use it: collect lines from every node, group them by shape and caller, rank by total time, profile the top suspects, fix, and compare.
  • What to protect: logged sources can contain sensitive data, so limit them, restrict access, and set retention.
  • What it cannot do: it cannot show stuck requests, queueing, network delays, merge time, or pipeline time, so combine it with tasks, statistics, and monitoring.

Keep in mind that details can change between Elasticsearch versions, so confirm exact setting names and options against the documentation of the release you run. With that habit, and the ideas in this guide, you can turn vague complaints about slowness into a clear list of causes and a steady stream of fixes.