use of org.opensearch.search.internal.SubSearchContext in project OpenSearch by opensearch-project.
the class TopHitsAggregatorFactory method createInternal.
@Override
public Aggregator createInternal(SearchContext searchContext, Aggregator parent, CardinalityUpperBound cardinality, Map<String, Object> metadata) throws IOException {
SubSearchContext subSearchContext = new SubSearchContext(searchContext);
subSearchContext.parsedQuery(searchContext.parsedQuery());
subSearchContext.explain(explain);
subSearchContext.version(version);
subSearchContext.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm);
subSearchContext.trackScores(trackScores);
subSearchContext.from(from);
subSearchContext.size(size);
if (sort.isPresent()) {
subSearchContext.sort(sort.get());
}
if (storedFieldsContext != null) {
subSearchContext.storedFieldsContext(storedFieldsContext);
}
if (docValueFields != null) {
FetchDocValuesContext docValuesContext = FetchDocValuesContext.create(searchContext.mapperService(), docValueFields);
subSearchContext.docValuesContext(docValuesContext);
}
if (fetchFields != null) {
FetchFieldsContext fieldsContext = new FetchFieldsContext(fetchFields);
subSearchContext.fetchFieldsContext(fieldsContext);
}
for (ScriptFieldsContext.ScriptField field : scriptFields) {
subSearchContext.scriptFields().add(field);
}
if (fetchSourceContext != null) {
subSearchContext.fetchSourceContext(fetchSourceContext);
}
if (highlightBuilder != null) {
subSearchContext.highlight(highlightBuilder.build(searchContext.getQueryShardContext()));
}
return new TopHitsAggregator(searchContext.fetchPhase(), subSearchContext, name, searchContext, parent, metadata);
}
Aggregations