Fluent builder for one Elasticsearch search request, wrapping the native SearchRequestBuilder behind the KSearchRequestBuilder API. Built via the search(List, Consumer) overload of ElasticSearchManager, which passes an instance of this class to the caller's callback so it can set the query, paging, sorting, aggregations and highlighting before the search is executed.

Group: Builders

Implements: KSearchRequestBuilder


Properties

PropertyReturnsDescription
pageSizeIntegerThe page size set on this request via setSize, or null if none has been set yet.
requestJsonStringThe native Elasticsearch request body for this search, as it currently stands, rendered to JSON.

Methods

getRequestJson() · getPageSize() · setQuery(QueryBuilder qb) · setQuery(QueryBuilder qb) · setSize(int i) · setTypes(String types) · addAggregation(AbstractAggregationBuilder b) · addAggregation(KAggregationBuilder b) · addFields(String fields) · addFields(Collection<String> fields) · setFetchSource(boolean b) · addSort(KSortBuilder order) · addSort(String sortField, KSortOrder order) · addHighlightedField(String field, int fragmentSize, int numFragments) · setFrom(int from) · setMinScore(float minScore) · setPaging(boolean b)

getRequestJson()

Returns: String

The native Elasticsearch request body for this search, as it currently stands, rendered to JSON.

getPageSize()

Returns: Integer

The page size set on this request via setSize, or null if none has been set yet.

setQuery(QueryBuilder qb)

Returns: DefaultKSearchRequestBuilder

Sets the query for this search using Kademi's own QueryBuilder abstraction.

ParameterDescription
qbthe query to run, converted to a native Elasticsearch query

setQuery(QueryBuilder qb)

Returns: KSearchRequestBuilder

Sets the query for this search using a native Elasticsearch QueryBuilder, for callers that need direct access to the underlying client API.

ParameterDescription
qbthe native Elasticsearch query to run

setSize(int i)

Returns: DefaultKSearchRequestBuilder

Sets the maximum number of hits to return in one page of results.

ParameterDescription
ithe page size

setTypes(String types)

Returns: DefaultKSearchRequestBuilder

Restricts the search to the given document types.

ParameterDescription
typesthe type names to search within

addAggregation(AbstractAggregationBuilder b)

Returns: DefaultKSearchRequestBuilder

Adds an aggregation to this search using a native Elasticsearch aggregation builder.

ParameterDescription
bthe aggregation to add

addAggregation(KAggregationBuilder b)

Returns: DefaultKSearchRequestBuilder

Adds an aggregation to this search using Kademi's own KAggregationBuilder abstraction.

ParameterDescription
bthe aggregation to add, converted to a native Elasticsearch aggregation

addFields(String fields)

Returns: DefaultKSearchRequestBuilder

Restricts which stored fields are returned for each hit.

ParameterDescription
fieldsthe field names to return

addFields(Collection<String> fields)

Returns: DefaultKSearchRequestBuilder

Restricts which stored fields are returned for each hit. If fields is null this call is ignored and no field restriction is applied.

ParameterDescription
fieldsthe field names to return, or null to leave the field list unchanged

setFetchSource(boolean b)

Returns: DefaultKSearchRequestBuilder

Controls whether the full document source is returned with each hit.

ParameterDescription
btrue to include the document source in results, false to omit it

addSort(KSortBuilder order)

Returns: DefaultKSearchRequestBuilder

Adds a sort order to this search using Kademi's own KSortBuilder abstraction.

ParameterDescription
orderthe sort to add, converted to a native Elasticsearch sort

addSort(String sortField, KSortOrder order)

Returns: DefaultKSearchRequestBuilder

Adds a sort order to this search for the given field.

ParameterDescription
sortFieldthe field to sort on
orderthe sort direction

addHighlightedField(String field, int fragmentSize, int numFragments)

Returns: KSearchRequestBuilder

Requests highlighted excerpts for the given field, for use in search-result snippets.

ParameterDescription
fieldthe field to highlight matches within
fragmentSizethe maximum length, in characters, of each highlighted fragment
numFragmentsthe maximum number of fragments to return for the field

setFrom(int from)

Returns: KSearchRequestBuilder

Sets the offset of the first hit to return, for paging through results without scrolling.

ParameterDescription
fromthe number of leading hits to skip

setMinScore(float minScore)

Returns: KSearchRequestBuilder

Excludes hits scoring below the given relevance threshold.

ParameterDescription
minScorethe minimum relevance score a hit must have to be included

setPaging(boolean b)

Returns: KSearchRequestBuilder

If true, the elasticsearch manager will iterate through results in pages, using the size property as the page size.

ParameterDescription
btrue to page through results
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.