The result of running a search, giving access to the matching hits, the total match count and any aggregations that were requested. Obtained by running a search through the search manager. Scripts normally read getHits to walk the results, or call useHits to stream them without holding a whole page of results in memory. The implementation returned is DefaultKSearchResponse.

Group: Managers

Extends: ToXContent


Properties

PropertyReturnsDescription
aggregationsKAggregationsThe aggregation results for this search, present only when the query asked for aggregations.
hitsKSearchHitsThe matching hits for this page of results, along with the total number of matches.

Methods

getAggregations()

Returns: KAggregations

The aggregation results for this search, present only when the query asked for aggregations.

getHits()

Returns: KSearchHits

The matching hits for this page of results, along with the total number of matches.

useHits(Consumer<KSearchHit> c)

Returns: void

Passes every hit in this response to the given function, one at a time. Prefer this over getHits when a query may match a large number of records, since the hits are handed over as they are read rather than held in memory together.

ParameterDescription
ccalled once for each hit

useHits(Consumer<KSearchHit> c, Integer maxRows)

Returns: void

Passes hits to the given function, stopping after the given number of rows. Use with scrolling queries to walk every hit a query matched, not just the first page.

ParameterDescription
ccalled once for each hit
maxRowsthe most rows to process, or null to iterate over all of them

breakUseHits()

Returns: void

Stops the iteration started by useHits. Call this from inside the function passed to useHits to break out of the loop early; it has no effect anywhere else.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.