forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort segments on timestamp in read only engine
Ordinary indices support sorting their segments on the timestamp when they have such a field defined in their mappings (see elastic#75195). This was not initially supported as a directory reader could not be created provding a leaf sorter, which is now possible in Lucene and we can make use of.
- Loading branch information
Showing
3 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...hots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/sort_segments_on_timestamp.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
setup: | ||
|
||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
properties: | ||
"@timestamp": | ||
type: date | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
|
||
# 1st segment | ||
- do: | ||
index: | ||
index: test | ||
body: { "foo": "bar1", "@timestamp": "2021-08-01" } | ||
refresh: true | ||
|
||
# 2nd segment | ||
- do: | ||
index: | ||
index: test | ||
body: { "foo": "bar2", "@timestamp": "2021-08-02" } | ||
refresh: true | ||
|
||
# 3rd segment missing @timestamp field | ||
- do: | ||
index: | ||
index: test | ||
body: { "foo": "bar1"} | ||
refresh: true | ||
|
||
- do: | ||
snapshot.create_repository: | ||
repository: repository-fs | ||
body: | ||
type: fs | ||
settings: | ||
location: "repository-fs" | ||
|
||
# Remove the snapshot if a previous test failed to delete it. | ||
# Useful for third party tests that runs the test against a real external service. | ||
- do: | ||
snapshot.delete: | ||
repository: repository-fs | ||
snapshot: snapshot | ||
ignore: 404 | ||
|
||
- do: | ||
snapshot.create: | ||
repository: repository-fs | ||
snapshot: snapshot | ||
wait_for_completion: true | ||
|
||
- do: | ||
indices.delete: | ||
index: test | ||
|
||
--- | ||
"Test that index segments are sorted on timestamp field if @timestamp field is defined in mapping": | ||
|
||
- do: | ||
searchable_snapshots.mount: | ||
repository: repository-fs | ||
snapshot: snapshot | ||
wait_for_completion: true | ||
body: | ||
index: test | ||
renamed_index: test-default-storage | ||
|
||
- match: { snapshot.snapshot: snapshot } | ||
- match: { snapshot.shards.failed: 0 } | ||
- match: { snapshot.shards.successful: 1 } | ||
|
||
# test that segments are sorted by @timestamp DESC | ||
- do: | ||
search: | ||
index: test-default-storage | ||
body: | ||
fields: [{ "field":"@timestamp", "format":"yyyy-MM-dd" }] | ||
- match: { hits.total.value: 3 } | ||
- match: { hits.hits.0.fields.@timestamp: ["2021-08-02"] } | ||
- match: { hits.hits.1.fields.@timestamp: ["2021-08-01"] } | ||
- is_false: hits.hits.2.fields.@timestamp |