mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 14:26:27 +00:00
Adapt ChunkedDataExtractor to removal of Aggregations#getProperty (elastic/x-pack-elasticsearch#1008)
Adapt ChunkedDataExtractor to removal of Aggregations#getProperty Original commit: elastic/x-pack-elasticsearch@01ee2fee58
This commit is contained in:
parent
0ae0f93994
commit
ef4de13ca4
@ -13,6 +13,8 @@ import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.metrics.max.Max;
|
||||
import org.elasticsearch.search.aggregations.metrics.min.Min;
|
||||
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractor;
|
||||
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory;
|
||||
import org.elasticsearch.xpack.ml.datafeed.extractor.ExtractorUtils;
|
||||
@ -44,7 +46,6 @@ public class ChunkedDataExtractor implements DataExtractor {
|
||||
|
||||
private static final String EARLIEST_TIME = "earliest_time";
|
||||
private static final String LATEST_TIME = "latest_time";
|
||||
private static final String VALUE_SUFFIX = ".value";
|
||||
|
||||
/** Let us set a minimum chunk span of 1 minute */
|
||||
private static final long MIN_CHUNK_SPAN = 60000L;
|
||||
@ -122,8 +123,10 @@ public class ChunkedDataExtractor implements DataExtractor {
|
||||
long latestTime = 0;
|
||||
long totalHits = response.getHits().getTotalHits();
|
||||
if (totalHits > 0) {
|
||||
earliestTime = (long) Double.parseDouble(aggregations.getProperty(EARLIEST_TIME + VALUE_SUFFIX).toString());
|
||||
latestTime = (long) Double.parseDouble(aggregations.getProperty(LATEST_TIME + VALUE_SUFFIX).toString());
|
||||
Min min = aggregations.get(EARLIEST_TIME);
|
||||
earliestTime = (long) min.getValue();
|
||||
Max max = aggregations.get(LATEST_TIME);
|
||||
latestTime = (long) max.getValue();
|
||||
}
|
||||
return new DataSummary(earliestTime, latestTime, totalHits);
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.metrics.max.Max;
|
||||
import org.elasticsearch.search.aggregations.metrics.min.Min;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractor;
|
||||
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory;
|
||||
@ -413,8 +415,12 @@ public class ChunkedDataExtractorTests extends ESTestCase {
|
||||
when(searchResponse.getHits()).thenReturn(searchHits);
|
||||
|
||||
Aggregations aggs = mock(Aggregations.class);
|
||||
when(aggs.getProperty("earliest_time.value")).thenReturn((double) earliestTime);
|
||||
when(aggs.getProperty("latest_time.value")).thenReturn((double) latestTime);
|
||||
Min min = mock(Min.class);
|
||||
when(min.getValue()).thenReturn((double) earliestTime);
|
||||
when(aggs.get("earliest_time")).thenReturn(min);
|
||||
Max max = mock(Max.class);
|
||||
when(max.getValue()).thenReturn((double) latestTime);
|
||||
when(aggs.get("latest_time")).thenReturn(max);
|
||||
when(searchResponse.getAggregations()).thenReturn(aggs);
|
||||
return searchResponse;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user