Result of one Elasticsearch search, wrapping the native SearchResponse behind the KSearchResponse API. Returned by every search overload of ElasticSearchManager. Supports both reading hits and aggregations directly, and iterating over hits with useHits, which transparently pages through scrolled results. Reading aggregations needs no page size; useHits requires one and throws without it.

Implements: KSearchResponse


Properties

PropertyReturnsDescription
aggregationsKAggregationsThe aggregation (facet) results computed alongside this search, if any aggregations were requested.
hitsKSearchHitsThe single page of hits returned directly by the backend for this search. For a scrolled search this is only the current page - use useHits to iterate over every page.
searchRequestBuilderSearchRequestBuilderThe native Elasticsearch request builder that produced this response, for callers that need direct access to the underlying client API.

Methods

getAggregations()

Returns: KAggregations

The aggregation (facet) results computed alongside this search, if any aggregations were requested.

getHits()

Returns: KSearchHits

The single page of hits returned directly by the backend for this search. For a scrolled search this is only the current page - use useHits to iterate over every page.

breakUseHits()

Returns: void

Stops a useHits loop from processing any further hits. Call from inside the callback passed to useHits to break out of it early.

getSearchRequestBuilder()

Returns: SearchRequestBuilder

The native Elasticsearch request builder that produced this response, for callers that need direct access to the underlying client API.

useHits(Consumer<KSearchHit> c)

Returns: void

Calls the given callback once for every hit in this search, transparently scrolling through every page of results until they are exhausted or breakUseHits is called. Requires that the search was given a page size, and throws if it was not - see useHits(c, maxRows).

ParameterDescription
ccalled once for each hit

useHits(Consumer<KSearchHit> c, Integer maxRows)

Returns: void

Calls the given callback once for every hit in this search, up to maxRows. Requires that the search was given a page size - search(json, pageSize, indexes) on SearchManager, or search(json, indexes, pageSize) on this manager - and throws if it was not. The check is on the page size alone, not on how many hits the query matched, so a call either always works or always fails rather than depending on how much data the account happens to hold.

ParameterDescription
ccalled once for each hit
maxRowsif null, will iterate over all rows. Otherwise will only process up to the given number
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.