Skip to content

Commit

Permalink
fixing TimeBasedIndicesIT
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke committed Jan 4, 2024
1 parent e26004a commit f584f2b
Showing 1 changed file with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Object>> 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<List<Object>> 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<List<Object>> 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<List<Object>> values = getValuesList(resp);
assertThat(values, hasSize(newDocs));
}
}
}
}
Expand Down

0 comments on commit f584f2b

Please sign in to comment.