All Products
Document Center

OpsRequest class

Last Updated: Sep 09, 2021


The OpsRequest class defines a query request and provides a set of functions that are used to obtain information from the query request. The OpsRequest class supports only the `OpsKvPairs getKVPairs()` function, which allows you to obtain an OpsKvPairs object. If custom parameters are defined in the KVPAIRS clause in a query, the OpsRequest class can be used to obtain the custom parameters during score calculation. We recommend that you use the OpsRequest class to obtain custom parameters during the initialization instead of score calculation of a score calculation object. The score function is called for each document that is involved in score calculation. If you obtain custom request parameters during score calculation, calculation costs are increased.




OpsKvPairs getKVPairs()

Obtains all the key-value pairs.

Function details

OpsKvPairs getKVPairs()

Obtains all the custom parameters in the form of key-value pairs. For more information about the OpsKvPairs class, see OpsKvPairs. Sample code:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.framework.OpsRequest;
import com.aliyun.opensearch.cava.framework.OpsKvPairs;
class BasicSimilarityScorer {
    long flag;
    boolean init(OpsScorerInitParams params) {
        OpsRequest request = params.getRequest();
        OpsKvPairs kvparis = request.getKVPairs();
        flag = kvpairs.getLong("flag"); // Obtain the value of the custom parameter whose key is flag from the KVPAIRS clause, and convert the value into a LONG value.
        return true;

    double score(OpsScoreParams params) {
        if (flag == 1) {
            //do something
        return 0.0;