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. Reading getAggregations works on any search. Iterating hits with useHits needs the search to have been given a page size, and throws without one; see useHits.
Group: Managers
Extends: ToXContent
Properties
| Property | Returns | Description |
|---|---|---|
| aggregations | KAggregations | The aggregation results for this search, present only when the query asked for aggregations. |
| hits | KSearchHits | The 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. Requires that the search was run with a page size - searchManager.search(query, pageSize, indexName) - and throws if it was not.
| Parameter | Description |
|---|---|
c | called 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. That needs a search run with a page size - searchManager.search(query, pageSize, indexName) - and throws if it was not given one, regardless of how many hits the query matched.
| Parameter | Description |
|---|---|
c | called once for each hit |
maxRows | the 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.