All Products
Search
Document Center

:OpsTimestamp

Last Updated:Feb 06, 2023

Overview

The OpsTimestamp class is equivalent to the TIMESTAMP data type that is supported by OpenSearch. An OpsTimestamp object represents a timestamp.

Constructor

Function

Description

OpsTimestamp(long timestamp)

Creates an OpsTimestamp object.

Functions

Function

Description

long getValue()

Obtains the value of the current timestamp.

Function details

OpsTimestamp(long timestamp)

Creates an OpsTimestamp object based on a specific timestamp. To maintain consistency with the TIMESTAMP data type that is supported by OpenSearch, we recommend that you set the timestamp to be accurate to milliseconds.

Parameter:

timestamp: the timestamp to be used to create an OpsTimestamp object.

long getValue()

Obtains the value of the current timestamp. In OpenSearch, values of the TIMESTAMP type are accurate to milliseconds. Return value: the current timestamp.

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.OpsDoc;
import com.aliyun.opensearch.cava.framework.OpsTimestamp;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return params.getDoc().requireAttribute("date");
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        OpsTimestamp timestamp = doc.docFieldTimestamp("date");
        if (timestamp == null) {
            doc.trace("timestamp is null");
        } else {
            doc.trace("timestamp value: ", timestamp.getValue());
        }
        return 0.0;
    }
}