org.elasticsearch.search.builder.SearchSourceBuilder.aggregations()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.elasticsearch.search.builder.SearchSourceBuilder.aggregations()方法的一些代码示例,展示了SearchSourceBuilder.aggregations()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SearchSourceBuilder.aggregations()方法的具体详情如下:
包路径:org.elasticsearch.search.builder.SearchSourceBuilder
类名称:SearchSourceBuilder
方法名:aggregations

SearchSourceBuilder.aggregations介绍

[英]Gets the bytes representing the aggregation builders for this request.
[中]获取表示此请求的聚合生成器的字节。

代码示例

代码示例来源:origin: floragunncom/search-guard

&& sr.source().aggregations() != null
  && sr.source().aggregations().getAggregatorFactories() != null
  && sr.source().aggregations().getAggregatorFactories().size() == 1
  && sr.source().size() == 0) {
AggregationBuilder ab = sr.source().aggregations().getAggregatorFactories().iterator().next();
if(     ab instanceof TermsAggregationBuilder
    && "terms".equals(ab.getType())

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Returns true iff the given search source builder can be early terminated by rewriting to a match none query. Or in other words
 * if the execution of the search request can be early terminated without executing it. This is for instance not possible if
 * a global aggregation is part of this request or if there is a suggest builder present.
 */
public static boolean canRewriteToMatchNone(SearchSourceBuilder source) {
  if (source == null || source.query() == null || source.query() instanceof MatchAllQueryBuilder || source.suggest() != null) {
    return false;
  }
  AggregatorFactories.Builder aggregations = source.aggregations();
  return aggregations == null || aggregations.mustVisitAllDocs() == false;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Returns a new ArraySearchPhaseResults instance. This might return an instance that reduces search responses incrementally.
 */
InitialSearchPhase.ArraySearchPhaseResults<SearchPhaseResult> newSearchPhaseResults(SearchRequest request, int numShards) {
  SearchSourceBuilder source = request.source();
  boolean isScrollRequest = request.scroll() != null;
  final boolean hasAggs = source != null && source.aggregations() != null;
  final boolean hasTopDocs = source == null || source.size() != 0;
  final boolean trackTotalHits = source == null || source.trackTotalHits();
  if (isScrollRequest == false && (hasAggs || hasTopDocs)) {
    // no incremental reduce if scroll is used - we only hit a single shard or sometimes more...
    if (request.getBatchedReduceSize() < numShards) {
      // only use this if there are aggs and if there are more shards than we should reduce at once
      return new QueryPhaseResultConsumer(this, numShards, request.getBatchedReduceSize(), hasTopDocs, hasAggs);
    }
  }
  return new InitialSearchPhase.ArraySearchPhaseResults<SearchPhaseResult>(numShards) {
    @Override
    ReducedQueryPhase reduce() {
      return reducedQueryPhase(results.asList(), isScrollRequest, trackTotalHits);
    }
  };
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent / json) addAggregation.
 */
public SearchSourceBuilder aggregations(byte[] aggregationsBinary) {
  return aggregations(aggregationsBinary, 0, aggregationsBinary.length);
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent) binary representation of addAggregation to use.
 */
public SearchRequestBuilder setAggregations(byte[] aggregations, int aggregationsOffset, int aggregationsLength) {
  sourceBuilder().aggregations(aggregations, aggregationsOffset, aggregationsLength);
  return this;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent / json) addAggregation.
 */
public SearchSourceBuilder aggregations(byte[] aggregationsBinary, int aggregationsBinaryOffset, int aggregationsBinaryLength) {
  return aggregations(new BytesArray(aggregationsBinary, aggregationsBinaryOffset, aggregationsBinaryLength));
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent) binary representation of addAggregation to use.
 */
public SearchRequestBuilder setAggregations(BytesReference aggregations) {
  sourceBuilder().aggregations(aggregations);
  return this;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent) binary representation of addAggregation to use.
 */
public SearchRequestBuilder setAggregations(Map aggregations) {
  sourceBuilder().aggregations(aggregations);
  return this;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent / json) addAggregation.
 */
public SearchSourceBuilder aggregations(XContentBuilder aggs) {
  return aggregations(aggs.bytes());
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent) binary representation of addAggregation to use.
 */
public SearchRequestBuilder setAggregations(byte[] aggregations) {
  sourceBuilder().aggregations(aggregations);
  return this;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent) binary representation of addAggregation to use.
 */
public SearchRequestBuilder setAggregations(XContentBuilder aggregations) {
  sourceBuilder().aggregations(aggregations);
  return this;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

if (source.aggregations() != null) {
  try {
    AggregatorFactories factories = source.aggregations().build(context, null);
    context.aggregations(new SearchContextAggregations(factories, multiBucketConsumerService.create()));
  } catch (IOException e) {

代码示例来源:origin: harbby/presto-connectors

/**
 * Sets a raw (xcontent / json) addAggregation.
 */
@SuppressWarnings("unchecked")
public SearchSourceBuilder aggregations(Map aggregations) {
  try {
    XContentBuilder builder = XContentFactory.contentBuilder(Requests.CONTENT_TYPE);
    builder.map(aggregations);
    return aggregations(builder);
  } catch (IOException e) {
    throw new ElasticsearchGenerationException("Failed to generate [" + aggregations + "]", e);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Returns true iff the given search source builder can be early terminated by rewriting to a match none query. Or in other words
 * if the execution of a the search request can be early terminated without executing it. This is for instance not possible if
 * a global aggregation is part of this request or if there is a suggest builder present.
 */
public static boolean canRewriteToMatchNone(SearchSourceBuilder source) {
  if (source == null || source.query() == null || source.query() instanceof MatchAllQueryBuilder || source.suggest() != null) {
    return false;
  } else {
    AggregatorFactories.Builder aggregations = source.aggregations();
    if (aggregations != null) {
      if (aggregations.mustVisitAllDocs()) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: com.floragunn/search-guard-6

&& sr.source().aggregations() != null
  && sr.source().aggregations().getAggregatorFactories() != null
  && sr.source().aggregations().getAggregatorFactories().size() == 1
  && sr.source().size() == 0) {
AggregationBuilder ab = sr.source().aggregations().getAggregatorFactories().iterator().next();
if(     ab instanceof TermsAggregationBuilder
    && "terms".equals(ab.getType())

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Returns a new SearchPhaseResults instance. This might return an instance that reduces search responses incrementally.
 */
InitialSearchPhase.SearchPhaseResults<SearchPhaseResult> newSearchPhaseResults(SearchRequest request, int numShards) {
  SearchSourceBuilder source = request.source();
  boolean isScrollRequest = request.scroll() != null;
  final boolean hasAggs = source != null && source.aggregations() != null;
  final boolean hasTopDocs = source == null || source.size() != 0;
  if (isScrollRequest == false && (hasAggs || hasTopDocs)) {
    // no incremental reduce if scroll is used - we only hit a single shard or sometimes more...
    if (request.getBatchedReduceSize() < numShards) {
      // only use this if there are aggs and if there are more shards than we should reduce at once
      return new QueryPhaseResultConsumer(this, numShards, request.getBatchedReduceSize(), hasTopDocs, hasAggs);
    }
  }
  return new InitialSearchPhase.SearchPhaseResults(numShards) {
    @Override
    public ReducedQueryPhase reduce() {
      return reducedQueryPhase(results.asList(), isScrollRequest);
    }
  };
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Returns a new ArraySearchPhaseResults instance. This might return an instance that reduces search responses incrementally.
 */
InitialSearchPhase.ArraySearchPhaseResults<SearchPhaseResult> newSearchPhaseResults(SearchRequest request, int numShards) {
  SearchSourceBuilder source = request.source();
  boolean isScrollRequest = request.scroll() != null;
  final boolean hasAggs = source != null && source.aggregations() != null;
  final boolean hasTopDocs = source == null || source.size() != 0;
  final boolean trackTotalHits = source == null || source.trackTotalHits();
  if (isScrollRequest == false && (hasAggs || hasTopDocs)) {
    // no incremental reduce if scroll is used - we only hit a single shard or sometimes more...
    if (request.getBatchedReduceSize() < numShards) {
      // only use this if there are aggs and if there are more shards than we should reduce at once
      return new QueryPhaseResultConsumer(this, numShards, request.getBatchedReduceSize(), hasTopDocs, hasAggs);
    }
  }
  return new InitialSearchPhase.ArraySearchPhaseResults(numShards) {
    @Override
    public ReducedQueryPhase reduce() {
      return reducedQueryPhase(results.asList(), isScrollRequest, trackTotalHits);
    }
  };
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Returns a new ArraySearchPhaseResults instance. This might return an instance that reduces search responses incrementally.
 */
InitialSearchPhase.ArraySearchPhaseResults<SearchPhaseResult> newSearchPhaseResults(SearchRequest request, int numShards) {
  SearchSourceBuilder source = request.source();
  boolean isScrollRequest = request.scroll() != null;
  final boolean hasAggs = source != null && source.aggregations() != null;
  final boolean hasTopDocs = source == null || source.size() != 0;
  final boolean trackTotalHits = source == null || source.trackTotalHits();
  if (isScrollRequest == false && (hasAggs || hasTopDocs)) {
    // no incremental reduce if scroll is used - we only hit a single shard or sometimes more...
    if (request.getBatchedReduceSize() < numShards) {
      // only use this if there are aggs and if there are more shards than we should reduce at once
      return new QueryPhaseResultConsumer(this, numShards, request.getBatchedReduceSize(), hasTopDocs, hasAggs);
    }
  }
  return new InitialSearchPhase.ArraySearchPhaseResults(numShards) {
    @Override
    public ReducedQueryPhase reduce() {
      return reducedQueryPhase(results.asList(), isScrollRequest, trackTotalHits);
    }
  };
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

if (source.aggregations() != null) {
  try {
    AggregatorFactories factories = source.aggregations().build(context, null);
    context.aggregations(new SearchContextAggregations(factories, multiBucketConsumerService.create()));
  } catch (IOException e) {

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

if (source.aggregations() != null) {
  try {
    AggregatorFactories factories = source.aggregations().build(context, null);
    factories.validate();
    context.aggregations(new SearchContextAggregations(factories));

相关文章

微信公众号

最新文章

更多

SearchSourceBuilder类方法