All Products
Search
Document Center

OpenSearch:SearchParamsBuilder class

Last Updated:Mar 18, 2026

This topic describes the functions of the SearchParamsBuilder class in the OpenSearch PHP software development kit (SDK).

Overview

The SearchParamsBuilder class is used to construct a parameter object for a SearchParams object.

Constructor

Function definition

mixed  OpenSearch\Util\SearchParamsBuilder::__construct($opts)

Parameters

Parameter

Type

Description

$opts

mixed

The content contains various query parameters.


Set the offset of the result set

Specifies the ordinal number of the first document to be returned in search results.

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setStart(integer $start)

Parameters

Parameter Name

Type

Description

$start

integer

Specifies the position in the search results from which to start returning documents.


Set the number of results to return

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setHits( $hits)

Parameters

Parameter name

Type

Description

$hits

integer

The number of results returned.


Set the format of the result set

Specifies the data format of return results. Supported formats are XML, JSON, and FULLJSON. Compared with the JSON format, the FULLJSON format supports extra fields such as variableValue.

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setFormat(String $format)

Parameters

Parameter name

Type

Description

$format

String

The response is in JSON format.


Set the name or ID of the application to search

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setAppName($appNames)

Parameters

Parameter name

Type

Description

$appNames

mixed

The application name.


Set the search keywords

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setQuery( $query)

Parameters

Parameter name

Type

Description

$query

String

The search keywords. The format is index_name:'keyword' [ AND | OR ... ].


Set kvpairs

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setKvPairs( $kvPairs)

Parameters

Parameter name

Type

Description

$kvPairs

String

The key-value pairs that you want to set.


Set the fields to return in the result set

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setFetchFields(array $fetchFields)

Parameters

Parameter name

Type

Description

$fetchFields

array

A list of fields to return. Example: array('a', 'b').


Specify the group value for a group query

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setRouteValue( $routeValue)

Parameters

Parameter

Type

Description

$routeValue

Mixed

The field values that are used for grouping.


Add a custom parameter to the Config clause

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setCustomConfig(String $key, Mixed $value)

Parameters

Parameter name

Type

Description

$key

String

You can set a custom parameter name.

$value

Mixed

You can set custom values for parameters.


Add a filter condition

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addFilter( $filter,  $condition)

Parameters

Parameter name

Type

Description

$filter

String

The filter condition. Example: a > 1.

$condition

String

The logical operator to connect the two filter conditions, such as AND and OR.


Set the filter condition

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setFilter($filterString)

Parameters

Parameter name

Type

Description

$filterString

mixed

The filter condition.


Add a sorting rule

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addSort( $field, $order)

Parameters

Parameter name

Type

Description

$field

String

The field based on which documents are to be sorted.

$order

mixed

SearchParamsBuilder::SORT_INCREASE or SearchParamsBuilder::SORT_DECREASE


Set the rough sort expression name

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setFirstRankName( $firstRankName)

Parameters

Parameter

Type

Description

$firstRankName

String

The name that you want to set for the rough sort expression.


Set the fine sort expression name

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setSecondRankName( $secondRankName)

Parameters

Parameter name

Type

Description

$secondRankName

String

The name that you want to set for the fine sort expression.


Set the aggregation configuration

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addAggregate( $agg)

Parameters

Parameter

Type

Description

$agg

array

The aggregation configurations that you want to specify.


Set the deduplication configuration

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addDistinct( $dist)

Parameters

Parameter name

Type

Description

$dist

array

The deduplication configurations that you want to specify.


Set the search result summary configuration

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addSummary( $summaryMeta)

Parameters

Parameter

Type

Description

$summaryMeta

array

The summary field configurations that you want to specify.


Add a query analysis configuration

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addQueryProcessor( $qpName)

Parameters

Parameter name

Type

Description

$qpName

array

Specifies the summary field configuration.


Add a function to disable

Function definition

void  OpenSearch\Util\SearchParamsBuilder::addDisableFunctions( $disabledFunction)

Parameters

Parameter

Type

Description

$disabledFunction

String

The specified configuration for the summary field.


Set a custom parameter

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setCustomParam( $key,  $value)

Parameters

Parameter name

Type

Description

$key

String

The key of the custom parameter.

$value

String

The value of the custom parameter.


Set the expiration time for a scroll scan

Sets a timeout period for each scroll query.

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setScrollExpire($expiredTime)

Parameters

Parameter name

Type

Description

$expiredTime

mixed

The TTL for the next scroll query. For example, to set the TTL to 3 minutes, set the value to 3m.


Set the scroll ID for a scroll scan

The ScrollId is returned by the previous scan.

Function definition

void  OpenSearch\Util\SearchParamsBuilder::setScrollId(String $scrollId)

Parameters

Parameter

Type

Description

$scrollId

String

You can set the scroll ID.


Get the SearchParams object

Function definition

\OpenSearch\Generated\Search\SearchParams     OpenSearch\Util\SearchParamsBuilder::build()
  • Returns a SearchParams object.