Skip to content

Commit

Permalink
Fix join keys ordering in a sequence (#76699) (#76912)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bpintea authored Aug 25, 2021
1 parent a422a6a commit d8040ea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ setup:
user: SYSTEM
id: 123
valid: true
- index:
_index: eql_test
_id: 4
- event:
- category: network
"@timestamp": 2020-02-06T12:34:56Z
user: ADMIN
id: 123
valid: true
- index:
_index: eql_test
_id: 5
- event:
- category: network
"@timestamp": 2020-02-07T12:34:56Z
user: SYSTEM
id: 123
valid: true
- index:
_index: eql_test
_id: 6
- event:
- category: network
"@timestamp": 2020-02-08T12:34:56Z
user: ADMIN
id: 123
valid: true
- index:
_index: eql_test
_id: 7
- event:
- category: network
"@timestamp": 2020-02-09T12:34:56Z
user: SYSTEM
id: 123
valid: true

---
# Testing round-trip and the basic shape of the response
Expand Down Expand Up @@ -382,3 +418,13 @@ setup:
catch: missing
eql.get_status:
id: $id
---
"Sequence checking correct join key ordering.":

- do:
eql.search:
index: eql_test
body:
query: 'sequence by user [network where valid == true] [network where true]'
- match: {hits.sequences.0.join_keys.0: "ADMIN"}
- match: {hits.sequences.1.join_keys.0: "SYSTEM"}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.xpack.eql.util.ReversedIterator;
import org.elasticsearch.xpack.ql.util.ActionListeners;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -548,6 +549,9 @@ private void payload(ActionListener<Payload> listener) {

// get results through search (to keep using PIT)
client.fetchHits(hits(completed), ActionListeners.map(listener, listOfHits -> {
if (criteria.get(0).descending()) {
Collections.reverse(completed);
}
SequencePayload payload = new SequencePayload(completed, listOfHits, false, timeTook());
close(listener);
return payload;
Expand Down

0 comments on commit d8040ea

Please sign in to comment.