Skip to content

Commit

Permalink
Instantiate facets/aggregations during the QUERY phase.
Browse files Browse the repository at this point in the history
In case of a DFS_QUERY_THEN_FETCH request, facets and aggregations are currently
instantiated during the DFS phase while they only become useful during the QUERY
phase. By instantiating during the QUERY phase instead, we can make better use
of recycling since objects will have a shorter life out of the recyclers.

Close elastic#5821
  • Loading branch information
jpountz authored and mikemccand committed Apr 24, 2014
1 parent 262dfd8 commit 1140410
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -84,9 +84,7 @@ protected Aggregator(String name, BucketAggregationMode bucketAggregationMode, A
assert factories != null : "sub-factories provided to BucketAggregator must not be null, use AggragatorFactories.EMPTY instead";
this.factories = factories;
this.subAggregators = factories.createSubAggregators(this, estimatedBucketsCount);
// TODO: change it to SEARCH_PHASE, but this would imply allocating the aggregators in the QUERY
// phase instead of DFS like it is done today
context.searchContext().addReleasable(this, Lifetime.CONTEXT);
context.searchContext().addReleasable(this, Lifetime.PHASE);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/elasticsearch/search/query/QueryPhase.java
Expand Up @@ -89,11 +89,15 @@ public QueryPhase(FacetPhase facetPhase, AggregationPhase aggregationPhase, Sugg
@Override
public void preProcess(SearchContext context) {
context.preProcess();
facetPhase.preProcess(context);
aggregationPhase.preProcess(context);
}

public void execute(SearchContext searchContext) throws QueryPhaseExecutionException {
// Pre-process facets and 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
facetPhase.preProcess(searchContext);
aggregationPhase.preProcess(searchContext);

searchContext.queryResult().searchTimedOut(false);

searchContext.searcher().inStage(ContextIndexSearcher.Stage.MAIN_QUERY);
Expand Down

0 comments on commit 1140410

Please sign in to comment.