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

OpenSearch:OpsGeoPoint

最終更新日:Apr 01, 2026

OpsGeoPoint は地理座標ポイントを表し、OpenSearch の GEO_POINT フィールド型に対応します。カスタム CAVA スコアラーでこれを使用してドキュメントの `geo_point` フィールドを読み取り、位置データをスコアリングロジックに組み込みます。たとえば、距離に基づくスコア減衰を適用したり、位置データが欠落しているドキュメントのランクを下げたりする場合に使用します。

コンストラクター

シグネチャ説明
OpsGeoPoint(double longitude, double latitude)指定された経度と緯度の値から OpsGeoPoint オブジェクトを作成します

パラメーター:

パラメーター説明
longitudedoubleポイントの経度
latitudedoubleポイントの緯度

メソッド

シグネチャ戻り値の型説明
getLongitude()doubleポイントの経度を返します
getLatitude()doubleポイントの緯度を返します

スコアラーでの geo_point フィールドの読み取り

doc.docFieldGeoPoint(fieldName) を呼び出して、ドキュメントの GEO_POINT フィールドを OpsGeoPoint オブジェクトとして取得します。フィールドが存在しないか、値がない場合、このメソッドは null を返します。座標にアクセスする前に null かどうかを確認してください。

次の例では、location フィールドを読み取り、経度と緯度の両方をログに記録します:

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.OpsGeoPoint;

class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        // location フィールドを必須属性として登録します
        return params.getDoc().requireAttribute("location");
    }

    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        OpsGeoPoint geopointValue = doc.docFieldGeoPoint("location");

        if (geopointValue == null) {
            // フィールドが存在しないか、値がない場合 — 適宜処理します
            doc.trace("geopoint is null");
        } else {
            doc.trace("longitude: ", geopointValue.getLongitude());
            doc.trace("latitude: ", geopointValue.getLatitude());
        }

        return 0.0;
    }
}