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
| Method | Return type | Description |
|---|---|---|
OpsDoc getDoc() | OpsDoc | Returns the document being scored, giving access to its attribute fields. |
OpsRequest getRequest() | OpsRequest | Returns 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;
}