すべてのプロダクト
Search
ドキュメントセンター

OpenSearch:OpsTimestamp

最終更新日:Apr 02, 2026

OpsTimestamp は、OpenSearch でサポートされている TIMESTAMP データの型のオブジェクト表現です。OpsTimestamp オブジェクトは、1 つのタイムスタンプを表します。

コンストラクター

シグネチャ説明
OpsTimestamp(long timestamp)OpsTimestamp オブジェクトをタイムスタンプ値から作成します。

パラメーター:

名前説明
timestamplongタイムスタンプ値です。OpenSearch の TIMESTAMP データの型との一貫性を維持するために、これをミリ秒精度に設定します。

メソッド

シグネチャ戻り値の型説明
getValue()long現在のタイムスタンプの値を返します。OpenSearch では、TIMESTAMP 型の値はミリ秒単位の精度です。

次の例は、カスタムスコアラーでドキュメントから TIMESTAMP フィールドを読み取る方法を示しています。フィールドが存在しない場合、docFieldTimestamp()null を返します。getValue() を呼び出す前に、必ず null をチェックしてください。

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;
    }
}