Java Code Examples for

The following examples show how to use . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File:    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public void execute(SearchContext searchContext) throws QueryPhaseExecutionException {
    // Pre-process aggregations as late as possible. In the case of a DFS_Q_T_F
    // request, preProcess is called on the DFS phase phase, this is why we pre-process them
    // here to make sure it happens during the QUERY phase

    boolean rescore = execute(searchContext, searchContext.searcher());

    if (rescore) { // only if we do a regular search

    if (searchContext.getProfilers() != null) {
        List<ProfileShardResult> shardResults = Profiler.buildShardResults(searchContext.getProfilers().getProfilers());
Example 2
Source File:    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void preProcess(SearchContext context) {
    if (context.aggregations() != null) {
        AggregationContext aggregationContext = new AggregationContext(context);

        List<Aggregator> collectors = new ArrayList<>();
        Aggregator[] aggregators;
        try {
            AggregatorFactories factories = context.aggregations().factories();
            aggregators = factories.createTopLevelAggregators(aggregationContext);
            for (int i = 0; i < aggregators.length; i++) {
                if (aggregators[i] instanceof GlobalAggregator == false) {
            if (!collectors.isEmpty()) {
                Collector collector = BucketCollector.wrap(collectors);
                if (context.getProfilers() != null) {
                    // TODO: report on child aggs as well
                    List<InternalProfileCollector> emptyList = Collections.emptyList();
                    collector = new InternalProfileCollector(collector, CollectorResult.REASON_AGGREGATION, emptyList);
                context.queryCollectors().put(AggregationPhase.class, collector);
        } catch (IOException e) {
            throw new AggregationInitializationException("Could not initialize aggregators", e);