Exemple #1
0
 public SearchResponse executeQuery(
     MetricConfig conf, String type, List<String> fields, BuilderCustomizer customizer) {
   SearchRequestBuilder builder =
       client
           .prepareSearch(MetricUtils.getIndexes(conf.getStart(), conf.getStop(), client))
           .setTypes(type)
           .setSearchType(SearchType.QUERY_AND_FETCH)
           .setSize((int) (conf.getStop() - conf.getStart()) / 10);
   for (String next : fields) {
     builder.addField(next);
   }
   BoolQueryBuilder query =
       QueryBuilders.boolQuery()
           .must(
               QueryBuilders.rangeQuery("timestamp")
                   .from(conf.getStart() - conf.getStep())
                   .to(conf.getStop())
                   .includeLower(false)
                   .includeUpper(true));
   for (String tag : conf.getTags()) {
     query = query.must(QueryBuilders.termQuery("tags", tag));
   }
   builder.setQuery(query);
   if (customizer != null) {
     customizer.customize(builder);
   }
   return builder.get();
 }
 private void explanFields(
     SearchRequestBuilder request, List<Field> fields, AggregationBuilder<?> groupByAgg)
     throws SqlParseException {
   for (Field field : fields) {
     if (field instanceof MethodField) {
       AbstractAggregationBuilder makeAgg = aggMaker.makeFieldAgg((MethodField) field, groupByAgg);
       if (groupByAgg != null) {
         groupByAgg.subAggregation(makeAgg);
       } else {
         request.addAggregation(makeAgg);
       }
     } else if (field instanceof Field) {
       request.addField(field.getName());
     } else {
       throw new SqlParseException("it did not support this field method " + field);
     }
   }
 }