このトピックでは、PolarDB-X のインテリジェント検索 (検索エンジン) の使用を開始する方法について、インスタンスの作成とアクセス資格情報の設定から、最初の全文検索とベクトル検索の実行までを説明します。
-
インテリジェント検索 (検索エンジン) は現在、招待制プレビューの段階であり、このフェーズでは課金されません。アクセスをご希望の場合は、チケットを送信してお問い合わせください。
-
このクイックスタートは、Elasticsearch または OpenSearch に関する基本的な知識があることを前提としています。詳細については、「OpenSearch ドキュメント」をご参照ください。
ステップ 1: インテリジェント検索インスタンスの作成
-
検索エンジンインスタンスの一覧ページに移動します。
-
ページの左上隅で、リージョンを選択します。
-
新規インスタンスの作成 をクリックします。購入または作成ページで、仕様シリーズ、ノード仕様、ノード数を選択し、設定を確認して送信します。
-
作成リクエストを送信すると、インスタンスの状態が 作成中 から 実行中 に変わります。初期化は通常 5〜10 分で完了します。
ステップ 2: アクセス認証情報の設定
-
インスタンス一覧で、インスタンス ID / 名前 をクリックしてインスタンス詳細ページを開きます。
-
アクセス設定 タブに切り替え、次の設定を行います:
-
ホワイトリスト: ホワイトリストグループの追加 をクリックし、お使いの業務環境の IP アドレスをホワイトリストに追加します。
-
アカウント管理: アカウントの新規作成 をクリックし、REST API 認証用のユーザー名とパスワードを作成します。
説明パスワードは 8〜32 文字で、大文字、小文字、数字、特殊文字をそれぞれ 1 つ以上含める必要があります。パスワードには、連続した文字 (例:
123やabc) や、よくある脆弱なパターンを含めることはできません。 -
接続情報: プライベートアドレス または パブリックアドレス と対応するポートを取得します。インターネット経由でインスタンスにアクセスするには、今すぐ有効化 をクリックしてパブリックエンドポイントを有効にします。
-
詳細な手順については、「接続とアクセス」をご参照ください。
ステップ 3: 接続性の検証
クライアント IP アドレスをホワイトリストに追加した後、curl を使用して接続性を検証します:
curl -XGET "http://<Search-engine-endpoint>:<port>" \
-u "<username>:<password>"
レスポンスの例:
{
"name": "52901553",
"cluster_name": "search-cluster-pxs-bjrf5gxxx",
"cluster_uuid": "6pwOq28yS4Smtxxx",
"version": {
"distribution": "opensearch",
"number": "3.6.0-SNAPSHOT",
"build_type": "tar",
"lucene_version": "10.4.0"
},
"tagline": "The OpenSearch Project: https://opensearch.org/"
}
ステップ 4: 最初のインデックスの作成
タイトルとコンテンツのフィールドを含む検索インデックスを作成します:
curl -XPUT "http://<Search-engine-endpoint>:<port>/my-first-index" \
-u "<username>:<password>" \
-H "Content-Type: application/json" \
-d '{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"title": { "type": "text", "analyzer": "ik_max_word" },
"content": { "type": "text", "analyzer": "ik_max_word" },
"category": { "type": "keyword" },
"publish_date": { "type": "date" }
}
}
}'
ステップ 5: テストデータの書き込み
_bulk API を使用して、複数のテストドキュメントを一括で書き込みます:
curl -XPOST "http://<Search-engine-endpoint>:<port>/my-first-index/_bulk" \
-u "<username>:<password>" \
-H "Content-Type: application/json" \
-d '
{"index": {"_id": "1"}}
{"title": "Introduction to PolarDB-X distributed database", "content": "PolarDB-X is a cloud-native distributed database that supports high-concurrency and high-availability online transaction processing.", "category": "Database", "publish_date": "2025-01-15"}
{"index": {"_id": "2"}}
{"title": "Getting started with OpenSearch full-text search", "content": "OpenSearch provides powerful full-text search capabilities and supports Chinese tokenization along with multiple query syntaxes.", "category": "Search", "publish_date": "2025-02-20"}
{"index": {"_id": "3"}}
{"title": "Vector search and AI applications", "content": "Vector search performs semantic similarity retrieval by calculating distances between vectors and is widely used in RAG and recommendation systems.", "category": "AI", "publish_date": "2025-03-10"}
'
ステップ 6: 全文検索の実行
「distributed database」を含むドキュメントを検索します:
curl -XPOST "http://<Search-engine-endpoint>:<port>/my-first-index/_search" \
-u "<username>:<password>" \
-H "Content-Type: application/json" \
-d '{
"query": {
"match": {
"content": "distributed database"
}
},
"highlight": {
"fields": {
"content": {}
}
}
}'
ステップ 7: (任意) ベクトル検索の例
-
ベクトル検索に対応したインデックスを作成します:
curl -XPUT "http://<Search-engine-endpoint>:<port>/my-vector-index" \ -u "<username>:<password>" \ -H "Content-Type: application/json" \ -d '{ "settings": { "index.knn": true, "number_of_shards": 1, "number_of_replicas": 1 }, "mappings": { "properties": { "title": { "type": "text" }, "embedding": { "type": "knn_vector", "dimension": 4, "method": { "engine": "faiss", "name": "hnsw", "space_type": "l2" } } } } }' -
ベクトルデータを書き込み、k-NN クエリを実行します:
curl -XPOST "http://<Search-engine-endpoint>:<port>/my-vector-index/_bulk" \ -u "<username>:<password>" \ -H "Content-Type: application/json" \ -d ' {"index": {"_id": "1"}} {"title": "Database technology", "embedding": [1.0, 2.0, 3.0, 4.0]} {"index": {"_id": "2"}} {"title": "Search engine", "embedding": [2.0, 3.0, 4.0, 5.0]} {"index": {"_id": "3"}} {"title": "Machine learning", "embedding": [5.0, 6.0, 7.0, 8.0]} ' curl -XPOST "http://<Search-engine-endpoint>:<port>/my-vector-index/_search" \ -u "<username>:<password>" \ -H "Content-Type: application/json" \ -d '{ "size": 2, "query": { "knn": { "embedding": { "vector": [1.5, 2.5, 3.5, 4.5], "k": 2 } } } }'
テストデータのクリーンアップ
テストインデックスが不要になった場合は、削除してください:
curl -XDELETE "http://<Search-engine-endpoint>:<port>/my-first-index" -u "<username>:<password>"
curl -XDELETE "http://<Search-engine-endpoint>:<port>/my-vector-index" -u "<username>:<password>"