When executing a search, a SearchParameter
instance must be passed to define the general conditions of the search.
For simple use cases SearchParameter.DEFAULT
can be used:
The attributes of SearchParameter
affect various aspects of the search execution and the search result.
The different parameter attributes can be defined via the SearchParameter
builder:
Parameter | Description | Default |
---|---|---|
maxResults | Maximum number of results | 10000 |
maxTrackTotalHits | Maximum number of total hits to track. If exceeded, tracking will be stopped and total hits count will be marked as not exact. | Elasticsearch server setting |
pageSize | Pagination page size | 100 |
pageIndex | Pagination page index (starts with 1) | 1 |
sortOptions | Result sort options (in descending priority) | unsorted |
language | Language for multilingual fields | language of user account |
fieldsToResolve | Names of fields to be resolved in search result | all fields |
aggregations | Aggregations of fields to build facets on | no aggregations |
optimizeExpressions | Should expressions be optimized? | true |
Sets the maximum number of results that can be paginated (default = 10000).
Sets the maximum number of total hits to track. If this number is exceeded by the number of current search hits, tracking will be stopped and the total hits count will be marked as not exact.
See also the Elasticsearch documentation.
Sets the pagination page size (default = 100
).
The default page size and the default max page size can be overridden in elasticsearch.properties
:
elasticsearch.service.default_page_size=100
elasticsearch.service.max_page_size=2000
Sets the pagination page index (starts with 1).
To get the next (or any other) page of a search result, the previous search must be executed again with the new page index.
A pagination sample can be found here.
Sets the result sort options (in descending priority).
The following example sorts first by id
in descending order, then by title
in ascending order:
Fields can only be sorted if they have been configured as sortable
in the corresponding field configuration.
Search results may be sorted by the relevance of the search hits:
The relevance of a search hit is calculated by Elasticsearch’s internal scoring algorithm.
A sort by relevance sample can be found here.
To sort by fields which contain multiple values (arrays), an array mode may be set:
Array mode | Description |
---|---|
MIN |
Use the lowest value. |
MAX |
Use the highest value. |
SUM |
Use the sum of all values. May only be used on number based array fields. |
AVG |
Use the average of all values. May only be used for for number based array fields. |
MEDIAN |
Use the median of all values. May only be used for number based array fields. |
A sort by array mode sample can be found here.
Sets the request language for multilingual fields (default = language of user account). This affects searching, sorting and faceting.
A prerequisite is that the query refers to a field that has been defined as multilingual
:
A multilingual search sample can be found here.
Sets the names of the fields to be resolved in the search result (default = all fields).
If an index document has many fields and not all fields are required in the result, the fields to be resolved (returned) can be specified:
Sets the aggregations of fields to build facets on (default = no aggregations).
A prerequisite is that the fields have been defined as aggregatable
:
Sets if expressions should be optimized (default = true
).
If true
, the passed expression is optimized internally and if necessary the complexity is reduced.
For debugging it can sometimes be helpful to set optimizeExpressions
to false
:
The Expression
optimizer can generally be enabled/disabled via elasticsearch.properties
(default = true
).
elasticsearch.service.optimize_expressions.enabled=true
If the Expression
optimizer is disabled in elasticsearch.properties
, the search parameter optimizeExpressions
is ignored.
with by the picturesafe-search community
Code licensed Apache License 2.0 Documentation licensed CC-BY-4.0