Skip to content

Commit d8040ea

Browse files
authored
Fix join keys ordering in a sequence (#76699) (#76912)
A sequence payload is constructed by providing one list of sequences and one for the hits. When fetching the list of hits though, the list of sequnces can be iterated in reverse order to build the hit references; meaning that the original list of sequences provided to the sequence payload needs reversing too.
1 parent a422a6a commit d8040ea

File tree

2 files changed

+50
-0
lines changed
  • x-pack/plugin/eql

2 files changed

+50
-0
lines changed

x-pack/plugin/eql/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/eql/10_basic.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ setup:
4141
user: SYSTEM
4242
id: 123
4343
valid: true
44+
- index:
45+
_index: eql_test
46+
_id: 4
47+
- event:
48+
- category: network
49+
"@timestamp": 2020-02-06T12:34:56Z
50+
user: ADMIN
51+
id: 123
52+
valid: true
53+
- index:
54+
_index: eql_test
55+
_id: 5
56+
- event:
57+
- category: network
58+
"@timestamp": 2020-02-07T12:34:56Z
59+
user: SYSTEM
60+
id: 123
61+
valid: true
62+
- index:
63+
_index: eql_test
64+
_id: 6
65+
- event:
66+
- category: network
67+
"@timestamp": 2020-02-08T12:34:56Z
68+
user: ADMIN
69+
id: 123
70+
valid: true
71+
- index:
72+
_index: eql_test
73+
_id: 7
74+
- event:
75+
- category: network
76+
"@timestamp": 2020-02-09T12:34:56Z
77+
user: SYSTEM
78+
id: 123
79+
valid: true
4480

4581
---
4682
# Testing round-trip and the basic shape of the response
@@ -382,3 +418,13 @@ setup:
382418
catch: missing
383419
eql.get_status:
384420
id: $id
421+
---
422+
"Sequence checking correct join key ordering.":
423+
424+
- do:
425+
eql.search:
426+
index: eql_test
427+
body:
428+
query: 'sequence by user [network where valid == true] [network where true]'
429+
- match: {hits.sequences.0.join_keys.0: "ADMIN"}
430+
- match: {hits.sequences.1.join_keys.0: "SYSTEM"}

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/execution/sequence/TumblingWindow.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.xpack.eql.util.ReversedIterator;
2727
import org.elasticsearch.xpack.ql.util.ActionListeners;
2828

29+
import java.util.Collections;
2930
import java.util.Iterator;
3031
import java.util.LinkedHashMap;
3132
import java.util.List;
@@ -548,6 +549,9 @@ private void payload(ActionListener<Payload> listener) {
548549

549550
// get results through search (to keep using PIT)
550551
client.fetchHits(hits(completed), ActionListeners.map(listener, listOfHits -> {
552+
if (criteria.get(0).descending()) {
553+
Collections.reverse(completed);
554+
}
551555
SequencePayload payload = new SequencePayload(completed, listOfHits, false, timeTook());
552556
close(listener);
553557
return payload;

0 commit comments

Comments
 (0)