Search in sources :

Example 1 with SubSearchContext

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);
}
Also used : FetchFieldsContext(org.opensearch.search.fetch.subphase.FetchFieldsContext) ScriptFieldsContext(org.opensearch.search.fetch.subphase.ScriptFieldsContext) FetchDocValuesContext(org.opensearch.search.fetch.subphase.FetchDocValuesContext) SubSearchContext(org.opensearch.search.internal.SubSearchContext)

Aggregations

FetchDocValuesContext (org.opensearch.search.fetch.subphase.FetchDocValuesContext)1 FetchFieldsContext (org.opensearch.search.fetch.subphase.FetchFieldsContext)1 ScriptFieldsContext (org.opensearch.search.fetch.subphase.ScriptFieldsContext)1 SubSearchContext (org.opensearch.search.internal.SubSearchContext)1