Search in sources :

Example 46 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project fess by codelibs.

the class BsSearchFieldLogCA method setName_Terms.

public void setName_Terms(String name, ConditionOptionCall<TermsAggregationBuilder> opLambda, OperatorCall<BsSearchFieldLogCA> aggsLambda) {
    TermsAggregationBuilder builder = regTermsA(name, "name");
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        SearchFieldLogCA ca = new SearchFieldLogCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) SearchFieldLogCA(org.codelibs.fess.es.log.cbean.ca.SearchFieldLogCA)

Example 47 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project fess by codelibs.

the class BsLabelToRoleCA method setRoleTypeId_Terms.

public void setRoleTypeId_Terms(String name, ConditionOptionCall<TermsAggregationBuilder> opLambda, OperatorCall<BsLabelToRoleCA> aggsLambda) {
    TermsAggregationBuilder builder = regTermsA(name, "roleTypeId");
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        LabelToRoleCA ca = new LabelToRoleCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) LabelToRoleCA(org.codelibs.fess.es.config.cbean.ca.LabelToRoleCA)

Example 48 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project fess by codelibs.

the class BsLabelToRoleCA method setLabelTypeId_Terms.

public void setLabelTypeId_Terms(String name, ConditionOptionCall<TermsAggregationBuilder> opLambda, OperatorCall<BsLabelToRoleCA> aggsLambda) {
    TermsAggregationBuilder builder = regTermsA(name, "labelTypeId");
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        LabelToRoleCA ca = new LabelToRoleCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) LabelToRoleCA(org.codelibs.fess.es.config.cbean.ca.LabelToRoleCA)

Example 49 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project incubator-skywalking by apache.

the class NetworkAddressEsUIDAO method getConjecturalApps.

@Override
public List<ConjecturalApp> getConjecturalApps() {
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NetworkAddressTable.TABLE);
    searchRequestBuilder.setTypes(NetworkAddressTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    int[] spanLayers = new int[] { SpanLayer.Database_VALUE, SpanLayer.Cache_VALUE, SpanLayer.MQ_VALUE };
    searchRequestBuilder.setQuery(QueryBuilders.termsQuery(NetworkAddressTable.COLUMN_SPAN_LAYER, spanLayers));
    searchRequestBuilder.setSize(0);
    TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(NetworkAddressTable.COLUMN_SERVER_TYPE).field(NetworkAddressTable.COLUMN_SERVER_TYPE).size(100);
    searchRequestBuilder.addAggregation(aggregationBuilder);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    List<ConjecturalApp> conjecturalApps = new LinkedList<>();
    Terms serverTypeTerms = searchResponse.getAggregations().get(NetworkAddressTable.COLUMN_SERVER_TYPE);
    serverTypeTerms.getBuckets().forEach(serverTypeTerm -> {
        int serverType = serverTypeTerm.getKeyAsNumber().intValue();
        ConjecturalApp conjecturalApp = new ConjecturalApp();
        conjecturalApp.setId(serverType);
        conjecturalApp.setNum((int) serverTypeTerm.getDocCount());
        conjecturalApps.add(conjecturalApp);
    });
    return conjecturalApps;
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) ConjecturalApp(org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp) LinkedList(java.util.LinkedList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 50 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project incubator-skywalking by apache.

the class ServiceMetricEsUIDAO method getServicesMetric.

@Override
public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource, Collection<Integer> serviceIds) {
    String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
    searchRequestBuilder.setTypes(ServiceMetricTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
    boolQuery.must().add(QueryBuilders.termsQuery(ServiceMetricTable.COLUMN_SERVICE_ID, serviceIds));
    boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
    searchRequestBuilder.setQuery(boolQuery);
    searchRequestBuilder.setSize(0);
    TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(100);
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_CALLS));
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
    searchRequestBuilder.addAggregation(aggregationBuilder);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    List<Node> nodes = new LinkedList<>();
    Terms serviceIdTerms = searchResponse.getAggregations().get(ServiceMetricTable.COLUMN_SERVICE_ID);
    serviceIdTerms.getBuckets().forEach(serviceIdBucket -> {
        int serviceId = serviceIdBucket.getKeyAsNumber().intValue();
        Sum callsSum = serviceIdBucket.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
        Sum errorCallsSum = serviceIdBucket.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
        ServiceNode serviceNode = new ServiceNode();
        serviceNode.setId(serviceId);
        serviceNode.setCalls((long) callsSum.getValue());
        serviceNode.setSla((int) (((callsSum.getValue() - errorCallsSum.getValue()) / callsSum.getValue()) * 10000));
        nodes.add(serviceNode);
    });
    return nodes;
}
Also used : ServiceNode(org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Node(org.apache.skywalking.apm.collector.storage.ui.common.Node) ServiceNode(org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)64 SignificantTermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder)20 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)14 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)13 Test (org.junit.Test)11 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)8 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)8 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)8 LinkedList (java.util.LinkedList)7 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)6 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)6 Arrays (java.util.Arrays)4 Map (java.util.Map)4 SearchRequest (org.apache.metron.indexing.dao.search.SearchRequest)4 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)4 AggregationBuilders (org.elasticsearch.search.aggregations.AggregationBuilders)4 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)4 Nullable (javax.annotation.Nullable)3 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)3