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
| Property | Returns | Description |
|---|---|---|
| pageSize | Integer | The page size set on this request via setSize, or null if none has been set yet. |
| requestJson | String | The 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.
| Parameter | Description |
|---|---|
qb | the 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.
| Parameter | Description |
|---|---|
qb | the native Elasticsearch query to run |
setSize(int i)
Returns: DefaultKSearchRequestBuilder
Sets the maximum number of hits to return in one page of results.
| Parameter | Description |
|---|---|
i | the page size |
setTypes(String types)
Returns: DefaultKSearchRequestBuilder
Restricts the search to the given document types.
| Parameter | Description |
|---|---|
types | the type names to search within |
addAggregation(AbstractAggregationBuilder b)
Returns: DefaultKSearchRequestBuilder
Adds an aggregation to this search using a native Elasticsearch aggregation builder.
| Parameter | Description |
|---|---|
b | the aggregation to add |
addAggregation(KAggregationBuilder b)
Returns: DefaultKSearchRequestBuilder
Adds an aggregation to this search using Kademi's own KAggregationBuilder abstraction.
| Parameter | Description |
|---|---|
b | the aggregation to add, converted to a native Elasticsearch aggregation |
addFields(String fields)
Returns: DefaultKSearchRequestBuilder
Restricts which stored fields are returned for each hit.
| Parameter | Description |
|---|---|
fields | the 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.
| Parameter | Description |
|---|---|
fields | the 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.
| Parameter | Description |
|---|---|
b | true 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.
| Parameter | Description |
|---|---|
order | the 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.
| Parameter | Description |
|---|---|
sortField | the field to sort on |
order | the sort direction |
addHighlightedField(String field, int fragmentSize, int numFragments)
Returns: KSearchRequestBuilder
Requests highlighted excerpts for the given field, for use in search-result snippets.
| Parameter | Description |
|---|---|
field | the field to highlight matches within |
fragmentSize | the maximum length, in characters, of each highlighted fragment |
numFragments | the 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.
| Parameter | Description |
|---|---|
from | the number of leading hits to skip |
setMinScore(float minScore)
Returns: KSearchRequestBuilder
Excludes hits scoring below the given relevance threshold.
| Parameter | Description |
|---|---|
minScore | the 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.
| Parameter | Description |
|---|---|
b | true to page through results |