OpsScoreParams

更新时间:
复制 MD 格式

OpsScoreParams encapsulates the context available inside a custom scoring function. OpenSearch automatically creates an OpsScoreParams object and passes it as the input parameter of double score(OpsScoreParams params) — no manual instantiation is needed.

Methods

MethodReturn typeDescription
OpsDoc getDoc()OpsDocReturns the document being scored, giving access to its attribute fields.
OpsRequest getRequest()OpsRequestReturns the current search request, giving access to request information.

Method details

OpsDoc getDoc()

Returns an OpsDoc object representing the document being scored. Use it to read attribute field values inside the scoring function.

For the full list of fields and methods available on OpsDoc, see OpsDoc.

OpsRequest getRequest()

Returns an OpsRequest object representing the current search request. Use it to read request information inside the scoring function.

For the full list of methods available on OpsRequest, see OpsRequest.

Example

The following example shows how to access the document and request context inside a score() function.

double score(OpsScoreParams params) {
    // Access the document being scored
    OpsDoc doc = params.getDoc();

    // Access the current search request
    OpsRequest request = params.getRequest();

    // Use doc and request to compute and return a custom score
    // See OpsDoc and OpsRequest for available methods
    return 0.0;
}