From f584f2bb5304a0ffe192da1fb2696099efedd9e1 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 4 Jan 2024 09:19:33 -0600 Subject: [PATCH] fixing TimeBasedIndicesIT --- .../xpack/esql/action/TimeBasedIndicesIT.java | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TimeBasedIndicesIT.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TimeBasedIndicesIT.java index a1fbee17ef8ec..c953a9cbdc2f4 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TimeBasedIndicesIT.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TimeBasedIndicesIT.java @@ -24,34 +24,35 @@ public class TimeBasedIndicesIT extends AbstractEsqlIntegTestCase { public void testFilter() { long epoch = System.currentTimeMillis(); assertAcked(client().admin().indices().prepareCreate("test").setMapping("@timestamp", "type=date", "value", "type=long")); - BulkRequestBuilder bulk = client().prepareBulk("test").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); - int oldDocs = between(10, 100); - for (int i = 0; i < oldDocs; i++) { - long timestamp = epoch - TimeValue.timeValueHours(between(1, 2)).millis(); - bulk.add(new IndexRequest().source("@timestamp", timestamp, "value", -i)); - } - int newDocs = between(10, 100); - for (int i = 0; i < newDocs; i++) { - long timestamp = epoch + TimeValue.timeValueHours(between(1, 2)).millis(); - bulk.add(new IndexRequest().source("@timestamp", timestamp, "value", i)); - } - bulk.get(); - { - EsqlQueryRequest request = new EsqlQueryRequest(); - request.query("FROM test | limit 1000"); - request.filter(new RangeQueryBuilder("@timestamp").from(epoch - TimeValue.timeValueHours(3).millis()).to("now")); - try (var resp = run(request)) { - List> values = getValuesList(resp); - assertThat(values, hasSize(oldDocs)); + try (BulkRequestBuilder bulk = client().prepareBulk("test").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)) { + int oldDocs = between(10, 100); + for (int i = 0; i < oldDocs; i++) { + long timestamp = epoch - TimeValue.timeValueHours(between(1, 2)).millis(); + bulk.add(new IndexRequest().source("@timestamp", timestamp, "value", -i)); } - } - { - EsqlQueryRequest request = new EsqlQueryRequest(); - request.query("FROM test | limit 1000"); - request.filter(new RangeQueryBuilder("@timestamp").from("now").to(epoch + TimeValue.timeValueHours(3).millis())); - try (var resp = run(request)) { - List> values = getValuesList(resp); - assertThat(values, hasSize(newDocs)); + int newDocs = between(10, 100); + for (int i = 0; i < newDocs; i++) { + long timestamp = epoch + TimeValue.timeValueHours(between(1, 2)).millis(); + bulk.add(new IndexRequest().source("@timestamp", timestamp, "value", i)); + } + bulk.get(); + { + EsqlQueryRequest request = new EsqlQueryRequest(); + request.query("FROM test | limit 1000"); + request.filter(new RangeQueryBuilder("@timestamp").from(epoch - TimeValue.timeValueHours(3).millis()).to("now")); + try (var resp = run(request)) { + List> values = getValuesList(resp); + assertThat(values, hasSize(oldDocs)); + } + } + { + EsqlQueryRequest request = new EsqlQueryRequest(); + request.query("FROM test | limit 1000"); + request.filter(new RangeQueryBuilder("@timestamp").from("now").to(epoch + TimeValue.timeValueHours(3).millis())); + try (var resp = run(request)) { + List> values = getValuesList(resp); + assertThat(values, hasSize(newDocs)); + } } } }