org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.series.ESMinHandler Maven / Gradle / Ivy
/**
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see .
*/
package org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.series;
import io.searchbox.core.SearchResult;
import io.searchbox.core.search.aggregation.MinAggregation;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder;
import org.graylog.plugins.views.search.elasticsearch.ESGeneratedQueryContext;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.ESPivot;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.ESPivotSeriesSpecHandler;
import org.graylog.plugins.views.search.searchtypes.pivot.Pivot;
import org.graylog.plugins.views.search.searchtypes.pivot.series.Min;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.ESPivot;
import org.graylog.plugins.views.search.elasticsearch.searchtypes.pivot.ESPivotSeriesSpecHandler;
import javax.annotation.Nonnull;
import java.util.Optional;
import java.util.stream.Stream;
public class ESMinHandler extends ESPivotSeriesSpecHandler {
@Nonnull
@Override
public Optional doCreateAggregation(String name, Pivot pivot, Min minSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
final MinAggregationBuilder min = AggregationBuilders.min(name).field(minSpec.field());
record(queryContext, pivot, minSpec, name, MinAggregation.class);
return Optional.of(min);
}
@Override
public Stream doHandleResult(Pivot pivot, Min pivotSpec,
SearchResult searchResult,
MinAggregation minAggregation,
ESPivot searchTypeHandler,
ESGeneratedQueryContext esGeneratedQueryContext) {
return Stream.of(ESPivotSeriesSpecHandler.Value.create(pivotSpec.id(), Min.NAME, minAggregation.getMin()));
}
}