Retrieving specific fields using the OpenSearch Java API

77 views Asked by At

At Elastic search we have fetchSource method at TopHitsAggregationBuilder. The relevant api is needed at Opensearch for TopHitsAggregationBuilder.

var aggBuilderTopHits = AggregationBuilders.topHits("duplicateDocuments").size(2).fetchSource(new String[] {"studentId", "requestUuid"}, null);

     /**
     * Indicate that _source should be returned with every hit, with an
     * "include" and/or "exclude" set which can include simple wildcard
     * elements.
     *
     * @param includes
     *            An optional list of include (optionally wildcarded)
     *            pattern to filter the returned _source
     * @param excludes
     *            An optional list of exclude (optionally wildcarded)
     *            pattern to filter the returned _source
     */

    public TopHitsAggregationBuilder fetchSource(@Nullable String[] includes, @Nullable String[] excludes) {
        FetchSourceContext fetchSourceContext = this.fetchSourceContext != null ? this.fetchSourceContext
            : FetchSourceContext.FETCH_SOURCE;
        this.fetchSourceContext = new FetchSourceContext(fetchSourceContext.fetchSource(), includes, excludes);
        return this;
    }

I tried to search for the opensearch document for fetching source. I couldn't find relevant solution for it.

0

There are 0 answers