You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user/ppl/cmd/reverse.rst
+63-27Lines changed: 63 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,21 @@ reverse
11
11
12
12
Description
13
13
============
14
-
|Using ``reverse`` command to reverse the display order of search results. The same results are returned, but in reverse order.
14
+
|Using ``reverse`` command to reverse the display order of search results. The behavior depends on the query context:
15
+
|
16
+
|**1. With existing sort**: Reverses the sort direction(s)
17
+
|**2. With @timestamp field (no explicit sort)**: Sorts by @timestamp in descending order
18
+
|**3. Without sort or @timestamp**: The command is ignored (no effect)
19
+
20
+
Behavior
21
+
========
22
+
The ``reverse`` command follows a three-tier logic:
23
+
24
+
1. **If there's an explicit sort command before reverse**: The reverse command flips all sort directions (ASC ↔ DESC)
25
+
2. **If no explicit sort but the index has an @timestamp field**: The reverse command sorts by @timestamp in descending order (most recent first)
26
+
3. **If neither condition is met**: The reverse command is ignored and has no effect on the result order
27
+
28
+
This design optimizes performance by avoiding expensive operations when reverse has no meaningful semantic interpretation.
15
29
16
30
Version
17
31
=======
@@ -26,16 +40,16 @@ reverse
26
40
27
41
Note
28
42
=====
29
-
The `reverse` command processes the entire dataset. If applied directly to millions of records, it will consume significant memory resources on the coordinating node. Users should only apply the `reverse` command to smaller datasets, typically after aggregation operations.
43
+
The ``reverse`` command is optimized to avoid unnecessary memory consumption. When applied without an explicit sort or @timestamp field, it is ignored. When used with an explicit sort, it efficiently reverses the sort direction(s) without materializing the entire dataset.
30
44
31
-
Example 1: Basic reverse operation
32
-
==================================
45
+
Example 1: Reverse with explicit sort
46
+
======================================
33
47
34
-
The example shows reversing the order of all documents.
48
+
The example shows reversing results after sorting by age in ascending order, effectively giving descending order.
35
49
36
50
PPL query::
37
51
38
-
os> source=accounts | fields account_number, age | reverse;
52
+
os> source=accounts | sort age | fields account_number, age | reverse;
39
53
fetched rows / total rows = 4/4
40
54
+----------------+-----+
41
55
| account_number | age |
@@ -47,33 +61,52 @@ PPL query::
47
61
+----------------+-----+
48
62
49
63
50
-
Example 2: Reverse with sort
51
-
============================
64
+
Example 2: Reverse with @timestamp field
65
+
=========================================
52
66
53
-
The example shows reversing results after sorting by age in ascending order, effectively giving descending order.
67
+
The example shows reverse on a time-series index automatically sorts by @timestamp in descending order (most recent first).
54
68
55
69
PPL query::
56
70
57
-
os> source=accounts | sort age | fields account_number, age | reverse;
Note: When the index contains an @timestamp field and no explicit sort is specified, reverse will sort by @timestamp DESC to show the most recent events first. This is particularly useful for log analysis and time-series data.
82
+
83
+
Example 3: Reverse ignored (no sort, no @timestamp)
0 commit comments