Search in sources :

Example 1 with ParsedFilters

use of org.opensearch.search.aggregations.bucket.filter.ParsedFilters in project kestra by kestra-io.

the class ElasticSearchExecutionRepository method executionCounts.

@Override
public List<ExecutionCount> executionCounts(List<Flow> flows, String query, ZonedDateTime startDate, ZonedDateTime endDate) {
    if (startDate == null) {
        startDate = ZonedDateTime.now().minusDays(30);
    }
    if (endDate == null) {
        endDate = ZonedDateTime.now();
    }
    SearchSourceBuilder sourceBuilder = this.searchSource(this.dateFilters(query, startDate, endDate), Optional.of(Collections.singletonList(AggregationBuilders.filters("FILTERS", flows.stream().map(flow -> new FiltersAggregator.KeyedFilter(flow.getNamespace() + "/" + flow.getFlowId(), QueryBuilders.boolQuery().must(QueryBuilders.termQuery("namespace", flow.getNamespace())).must(QueryBuilders.termQuery("flowId", flow.getFlowId())))).toArray(FiltersAggregator.KeyedFilter[]::new)))), null);
    try {
        SearchRequest searchRequest = searchRequest(INDEX_NAME, sourceBuilder, false);
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        List<ExecutionCount> result = new ArrayList<>();
        ((ParsedFilters) searchResponse.getAggregations().get("FILTERS")).getBuckets().forEach(filtersBuckets -> {
            final String key = filtersBuckets.getKeyAsString();
            result.add(new ExecutionCount(key.split("/")[0], key.split("/")[1], filtersBuckets.getDocCount()));
        });
        return result;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : TaskRun(io.kestra.core.models.executions.TaskRun) RequestOptions(org.opensearch.client.RequestOptions) java.util(java.util) ExecutionRepositoryInterface(io.kestra.core.repositories.ExecutionRepositoryInterface) Flow(io.kestra.core.models.executions.statistics.Flow) ParsedStringTerms(org.opensearch.search.aggregations.bucket.terms.ParsedStringTerms) ZonedDateTime(java.time.ZonedDateTime) DateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) DateHistogramInterval(org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval) ExecutionCount(io.kestra.core.models.executions.statistics.ExecutionCount) ParsedDateHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedDateHistogram) State(io.kestra.core.models.flows.State) LongBounds(org.opensearch.search.aggregations.bucket.histogram.LongBounds) AggregationBuilder(org.opensearch.search.aggregations.AggregationBuilder) FiltersAggregator(org.opensearch.search.aggregations.bucket.filter.FiltersAggregator) Nullable(io.micronaut.core.annotation.Nullable) Duration(java.time.Duration) Pageable(io.micronaut.data.model.Pageable) SearchRequest(org.opensearch.action.search.SearchRequest) SearchResponse(org.opensearch.action.search.SearchResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) ParsedFilters(org.opensearch.search.aggregations.bucket.filter.ParsedFilters) QueryBuilders(org.opensearch.index.query.QueryBuilders) Filter(org.opensearch.search.aggregations.bucket.filter.Filter) TopHits(org.opensearch.search.aggregations.metrics.TopHits) Singleton(jakarta.inject.Singleton) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) ScoreMode(org.apache.lucene.search.join.ScoreMode) Terms(org.opensearch.search.aggregations.bucket.terms.Terms) Execution(io.kestra.core.models.executions.Execution) Collectors(java.util.stream.Collectors) DailyExecutionStatistics(io.kestra.core.models.executions.statistics.DailyExecutionStatistics) ZoneId(java.time.ZoneId) AggregationBuilders(org.opensearch.search.aggregations.AggregationBuilders) ParsedStats(org.opensearch.search.aggregations.metrics.ParsedStats) ArrayListTotal(io.kestra.core.repositories.ArrayListTotal) ExecutorsUtils(io.kestra.core.utils.ExecutorsUtils) TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) IndexSettings(org.opensearch.index.IndexSettings) ModelValidator(io.kestra.core.models.validations.ModelValidator) NestedAggregationBuilder(org.opensearch.search.aggregations.bucket.nested.NestedAggregationBuilder) Inject(jakarta.inject.Inject) ParsedNested(org.opensearch.search.aggregations.bucket.nested.ParsedNested) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) SearchRequest(org.opensearch.action.search.SearchRequest) ExecutionCount(io.kestra.core.models.executions.statistics.ExecutionCount) FiltersAggregator(org.opensearch.search.aggregations.bucket.filter.FiltersAggregator) IOException(java.io.IOException) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

Execution (io.kestra.core.models.executions.Execution)1 TaskRun (io.kestra.core.models.executions.TaskRun)1 DailyExecutionStatistics (io.kestra.core.models.executions.statistics.DailyExecutionStatistics)1 ExecutionCount (io.kestra.core.models.executions.statistics.ExecutionCount)1 Flow (io.kestra.core.models.executions.statistics.Flow)1 State (io.kestra.core.models.flows.State)1 ModelValidator (io.kestra.core.models.validations.ModelValidator)1 ArrayListTotal (io.kestra.core.repositories.ArrayListTotal)1 ExecutionRepositoryInterface (io.kestra.core.repositories.ExecutionRepositoryInterface)1 ExecutorsUtils (io.kestra.core.utils.ExecutorsUtils)1 Nullable (io.micronaut.core.annotation.Nullable)1 Pageable (io.micronaut.data.model.Pageable)1 Inject (jakarta.inject.Inject)1 Singleton (jakarta.inject.Singleton)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1