Atlas Search インデックスの管理
項目一覧
Atlas Searchインデックスは、データを簡単に検索可能な形式に分類するデータ構造です。タームとタームを含むドキュメントの間をマッピングします。 Atlas Search インデックスを使用すると、特定の識別子を使用してドキュメントをすばやく検索できます。 Atlas Search を使用して Atlas クラスター内のデータをクエリするには、Atlas Searchインデックスを設定する必要があります。
Atlas Search インデックスは、単一または複数のフィールドで作成できます。データのソートやフィルタリングによく使用するフィールドはインデックスを作成して、クエリ時に関連データを含むドキュメントをすばやく取得できるようにすることをお勧めします。
Considerations
インデックスの整合性と再構築
Atlas Search インデックスを定義したコレクションに変更を加えた場合、クエリですぐに最新データを使用できない場合があります。ただし、mongot
は変更ストリームをモニターするため、保存済みデータのコピーがアップデート可能になるため、Atlas Search インデックスは結果整合性があります。
mongot
mongot
インデックス定義を変更すると、mongod
はバックグラウンドで新しいインデックスを自動的に再ビルドすると同時に、古いインデックスでクエリを引き続き処理してダウンタイムが発生しないことを確認します。これは、 と プロセスを同じノードに配置した場合、および プロセスを異なるノードに配置した場合に発生します。 Atlas は、 の保存時の暗号化を有効または無効にすると、インデックスも再ビルドします。
検索配置のトポロジーを変更すると、Atlas Search は古いノードを削除する前に、新しいノードにインデックスをプロビジョニングして構築し、クエリのダウンタイムを発生させません。
mongod
プロセスと mongot
プロセスの両方が 同じノードで実行される配置の場合、Atlas Search がインデックスの再構築を必要とする変更(インデックスの更新 が必要な Atlas Search の機能など)を導入した場合、Atlas Search は追加の を自動的に配置します。ノードは無料でインデックスを構築できますが、古いノードは引き続きクエリを処理します。
警告
Atlas Search インデックスが既に存在するコレクションをシャーディングする場合、コレクションがシャードに表示され始めるときにクエリのダウンタイムが短時間発生することがあります。また、シャードを Atlas Search インデックスなどのシャーディングされたコレクションに追加する場合、追加されたシャードで最初の同期プロセスが完了するまで、そのコレクションに対する検索クエリは失敗します。詳しくは、「最初の同期プロセス」を参照してください。
重要
$out集計ステージを使用して既存の Atlas Searchインデックスを持つコレクションを変更する場合は、その検索インデックスを削除して再作成する必要があります。可能であれば、 の代わりに $merge $out
を使用することを検討してください。
専用検索ノード
専用の検索ノードをデプロイすることにより、パフォーマンス、スケーラビリティ、およびリソース分離を向上できます。検索ノードをデプロイした場合、次の点を考慮してください。
シャードを追加、調整すると、Atlas Search インデックスの再構築がトリガーされます。 インデックスの再構築中、データは最新でない場合があります。 そのため、追加、調整されたシャードのデータにクエリを実行すると、失敗したり不正確な結果が返されることがあります。
Atlas Search インデックスでコレクションを再シャーディングする と、再シャーディング操作の完了時にコレクションの Atlas Search インデックスを使用できなくなります。操作が完了してから、Atlas Search インデックスを削除して新しい作成する必要があります。
データベースのプライマリシャードを変更するためにコマンドを発行する場合、操作の完了時にこのデータベースにあるシャーディングされていないコレクションで Atlas Search インデックスを使用できなくなります。
movePrimary
操作が完了したら、Atlas Search インデックスを削除して新しい Atlas Search インデックスを作成し直す必要があります。
Atlas Searchノードのアーキテクチャの詳細については、「 Atlas Search 配置オプション 」を参照してください。
必要なアクセス権
このガイドで説明されている Atlas Searchインデックスアクションを実行するために必要なユーザー特権にアクセスするには、 プロジェクトユーザーロール または データベースユーザーロール を割り当てられます。
次の表は、指定された Atlas Search アクションに対して次のプロジェクト ロールがサポートするアクセス モードを示しています。
ロール | Atlas Search アクション | Atlas UI | Atlas CLI | Atlas API [1] |
---|---|---|---|---|
| Atlas Search インデックスとアナライザを表示します。 | ✓ | ✓ | |
| Atlas Search インデックスとアナライザを作成、表示、更新、削除します。 | ✓ | ✓ | ✓ |
Atlas Search インデックスを作成、表示、更新、および削除するため。 | ✓ | ✓ | ✓ |
[1] | 各ロールは、Atlas Administration API で Atlas Search API エンドポイントのサブセットまたはフルセットを呼び出す権限を付与します。各ロールがアクセスを許可する API エンドポイントの説明については、Atlas Search アクション列を参照してください。 |
次のMongoDBデータベース ロールは、指定されたAtlas Search インデックス特権アクションをサポートします。
アクションの説明 | データベース ロール | Atlas Search インデックス特権アクション |
---|---|---|
Atlas Searchインデックスの表示 | ||
Atlas Searchインデックスの作成 | ||
Atlas Searchインデックスの編集 | ||
Atlas Searchインデックスの削除 |
Atlas Search インデックスの作成
次のチュートリアルでは、選択した方法を使用して Atlas Searchインデックスを作成する方法について説明します。
sample_mflix.movies
コレクションのインデックスを作成する例チュートリアルについては、「Atlas Search クイック スタート」を参照してください。クエリ設定を満たすインデックスを定義する方法の概念については、「インデックスの定義」を参照してください。
Atlas Search は、Atlas CLI を使用して作成したローカル Atlas 配置で使用することもできます。 詳細については、「 Atlas 配置のローカル配置の作成 」を参照してください。
➤ [ 言語を選択 ] ドロップダウン メニューを使用して、このセクションの手順の言語を設定します。
Atlas Search APIを使用して Atlas Searchインデックスを作成するには、次の手順に従います。
POST
リクエストを送信します。
POST
リクエストを search/indexes
エンドポイントに送信します。
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --include \ --request POST "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes" \ --data ' { "collectionName": "<collection-name>", "database": "<database-name>", "name": "<index-name>", "type": "search", "definition": { "analyzer": "<analyzer-name>", "searchAnalyzer": "<analyzer-name>", "mappings": { "dynamic": <boolean>, "fields": { <field-definition> } }, "numPartitions": <integer>, "analyzers": [ { <custom-analyzer-definition> } ], "storedSource": <boolean> | { <stored-source-definition> }, "synonyms": [ { <synonym-mapping-definition> } ] } }'
このエンドポイントの構文とパラメータについて詳しくは、「作成」を参照してください。
Atlas CLI を使用して Atlas Searchインデックスを作成するには、次の手順に従います。
クラウド配置
Atlas CLI を使用してクラスターの検索インデックスを作成するには、次のコマンドを実行します。
atlas clusters search indexes create [indexName] [options]
コマンド構文とパラメーターの詳細については、Atlas CLI ドキュメントの「atlas clusters search indexes create」を参照してください。
ローカル配置
Atlas CLI を使用して指定したデプロイの検索インデックスを作成するには、次のコマンドを実行します。
atlas deployments search indexes create [indexName] [options]
コマンド構文とパラメーターの詳細については、Atlas CLI ドキュメントの「atlas deployments search indexes create」を参照してください。
Atlas CLI を使用してローカル Atlas 配置を作成する方法の詳細については、「 ローカル Atlas 配置の作成 」を参照してください。
例
次の例は、 atlas clusters
またはatlas deployments
コマンドを使用して、構成ファイルを使用して非対話型モードで Atlas Search インデックスを作成する方法を示しています。
Atlas UIを使用して Atlas Searchインデックスを作成するには、次の手順に従います。
Atlas Atlasで、プロジェクトの {0 ページにGoします。GoClusters
警告
ナビゲーションの改善が進行中
現在、新しく改善されたナビゲーション エクスペリエンスを展開しています。次の手順が Atlas UIのビューと一致しない場合は、プレビュー ドキュメントを参照してください。
まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー
まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。
まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。
[ Clusters (クラスター) ] ページが表示されます。
インデックスの設定を開始します。
ページで次の選択を行い、Next をクリックしてください。
Search Type | Atlas Searchインデックスタイプを選択します。 |
Index Name and Data Source | 以下の情報を指定してください。
|
Configuration Method | For a guided experience, select Visual Editor. To edit the raw index definition, select JSON Editor. |
注意
Atlas Searchインデックスの名前は、デフォルトで default
です。この名前を維持する場合、インデックスは、演算子に別の index
オプションを指定していない Atlas Search クエリのデフォルトの検索インデックスになります。複数のインデックスを作成する場合は、インデックス間で一貫した記述的な命名規則を維持することをお勧めします。
Index Configurations セクションでデフォルトの Atlas Search インデックス構成設定を確認します。
デフォルトのインデックス定義は、ドキュメント内のフィールドを動的にマッピングしたもので、どのコレクションでも機能します。
インデックス定義をカスタマイズするには、次のインデックス構成を確認してください。
ビジュアル エディター フィールド | 説明 | 必要性 |
---|---|---|
Index Analyzer | 任意 | |
Search Analyzer | 任意 | |
Dynamic Mapping | フィールドの動的マッピングまたは静的マッピングを指定します。 デフォルトでは 、動的マッピングは有効になっています。動的マッピングを無効にするには、 動的マッピングと静的マッピングについて詳しくは、「 フィールドマッピングの定義 」を参照してください。
| 必須 |
フィールド名 | 説明 | 必要性 |
---|---|---|
| 任意 | |
| 任意 | |
| フィールドの動的マッピングまたは静的マッピングを指定します。動的マッピングを無効にするには、 | 必須 |
これらのインデックス定義設定の詳細については、「 インデックス リファレンス 」を参照してください。
デフォルト設定に問題がなければ、先に進みます。Atlas Search インデックスを再定義する場合は、次の手順に進みます。
Atlas Search インデックスを微調整して、追加設定を構成します。
以下の設定のいずれかを変更するには [Refine Your Index] をクリックします。
フィールド名説明必要性Field Mappings
Index Configurations セクションの Dynamic Mapping が無効になっている場合は必須です。
インデックスを作成するフィールドを指定します。
Add Field MappingをクリックするとAdd Field Mappingウィンドウが開きます。
フィールドに関する次の情報を指定します。
Field name - インデックスを作成するフィールドの名前。
Data Type - フィールドのデータ型。サポートされているデータ型とそのオプションについて詳しくは、「データ型」を参照してください。
(任意)追加のプロパティを指定します。
追加の構成オプションのテーブルは Add Field Mappingウィンドウに表示されます。これらのプロパティは、最後の手順で選択したデータ型によって異なります。
サポートされているデータ型とそのオプションについて詳しくは、「データ型」を参照してください。
(任意)マルチフィールドを追加します。
フィールドをインデックスための代替フィールドアナライザを設定するには、Add Multi Field をクリックします。詳細については、「 マルチアナライザ 」を参照してください。
[Add] をクリックしてフィールドを追加します。
Actions 列のフィールドの省略記号(...)アイコンをクリックして、次の操作を実行できます。
構成を変更するには、Edit をクリックします。
フィールドに追加のデータ型を設定するには、Add Data Type をクリックします。
Delete をクリックして、インデックスからフィールドを削除します。
フィールドマッピングの定義の詳細については、「 インデックス リファレンス 」を参照してください。
mappings.fields
JSON 設定に対応します。条件付き
Stored Source Fields
クエリ時間検索用に Atlas Search に保存するフィールドを指定します。サポートされているすべての データ型 のフィールドを Atlas Search に保存できます。
フィールドの保存の詳細については、「Atlas Search インデックスに保存されたソース フィールドの定義」を参照してください。
storedSource
JSON 設定に対応します。任意
Synonyms Mappings
インデックスで使用する シノニム マッピング を指定します。
シノニム(同意語)マッピング を使用して、 同じアナライザで分析されたフィールドのみをクエリできます。
シノニム マッピングの詳細については、「 Atlas Search インデックスでのシノニム マッピングの定義 」を参照してください。
synonyms
JSON 設定に対応します。任意。
Index Partitions
フィールドオブジェクトが 2.1 00 億を超える場合に使用するパーティションの数。
numPartitions
JSON 設定に対応します。任意。
[Save Changes] をクリックします。
次のいずれかの設定をインデックスに追加します。
フィールド名説明必要性mappings.fields
mappings.dynamic
がfalse
の場合は必須です。インデックスを作成するフィールドを指定します。詳しくは「フィールドマッピングの定義」を参照してください。
条件付き
storedSource
クエリ時間検索用に Atlas Search に保存するフィールドを指定します。サポートされているすべての データ型 のフィールドを Atlas Search に保存できます。
フィールドの保存の詳細については、「Atlas Search インデックスに保存されたソース フィールドの定義」を参照してください。
任意
synonyms
インデックスで使用する シノニム マッピング を指定します。
シノニム(同意語)マッピング を使用して、 同じアナライザで分析されたフィールドのみをクエリできます。
シノニム マッピングの詳細については、「 Atlas Search インデックスでのシノニム マッピングの定義 」を参照してください。
任意
numPartitions
フィールドオブジェクトが 2.1 00 億を超える場合に使用するパーティションの数。
任意。
これらのインデックス定義設定の詳細については、「 インデックス リファレンス 」を参照してください。
[Next] をクリックします。
任意。Visual Editor を使用すると、インデックス定義の下書きを保存または削除できます。
注意
デフォルトのインデックス定義 を下書きとして保存することはできません。 Visual Editor を使用しており、インデックス定義に静的マッピングが含まれている場合は、インデックス定義をドラフトとして保存できます。
[Cancel] をクリックします。
[Save Draft] または [Delete Draft] をクリックします。
重要
保留中のインデックス ドラフトがある場合は、インデックスを新規作成できません。
を使用して Atlas Searchインデックスを作成するには、次の手順に従います。mongosh
mongosh
を使用して接続します。
詳しくは、「 mongosh
経由で接続 」を参照してください。
Atlas Search インデックスの作成。
db.collection.createSearchIndex()
メソッドを使用します。
コマンドの構文は です。インデックス名を省略すると、Atlas Search はインデックスにdefault
という名前を付けます。詳細については、「 インデックス リファレンス 」を参照してください。
db.<collection>.createSearchIndex( "<index-name>", { /* search index definition */ } )
例
example-index
という名前のインデックスを作成し、movies
コレクションのフィールドに動的にインデックスするには、次のコマンドを実行します。
db.movies.createSearchIndex( "example-index", { mappings: { dynamic: true } } )
example-index
MongoDB Compassを使用して Atlas Searchインデックスを作成する方法
MongoDB Compass経由で Atlas クラスターに接続します。
Compass を開き、Atlas クラスターに接続します。詳しくは、「 Compass 経由で接続 」を参照してください。
Atlas Searchインデックスを作成します。
[ Indexesタブをクリックし、[ ] を選択します。Search Indexes
[ Create Indexをクリックして、インデックス作成ダイアログボックスを開きます。
インデックスの名前を指定します。
Atlas Searchインデックスの名前は、デフォルトで
default
です。この名前を維持する場合、インデックスは、演算子に別のindex
オプションを指定していない Atlas Search クエリのデフォルトの検索インデックスになります。複数のインデックスを作成する場合は、インデックス間で一貫した記述的な命名規則を維持することをお勧めします。JSON Atlas Searchインデックス定義を指定します。
1 { 2 "analyzer": "<analyzer-for-index>", 3 "searchAnalyzer": "<analyzer-for-query>", 4 "mappings": { 5 "dynamic": <boolean>, 6 "fields": { <field-definition> } 7 }, 8 "numPartitions": <integer>, 9 "analyzers": [ <custom-analyzer> ], 10 "storedSource": <boolean> | { 11 <stored-source-definition> 12 }, 13 "synonyms": [ 14 { 15 <synonym-mapping-definition> 16 } 17 ] 18 } 19 [Create Search Index] をクリックします。
C ドライバーを使用して Atlas Search インデックスを作成するには、アプリケーションで検索インデックスを定義し、mongoc_collection_command_simple()
メソッドを呼び出します。
注意
Atlas Search インデックス マネジメントのメソッドは非同期で実行されます。ドライバー メソッドは、正常に実行されたことを確認する前に戻ることができます。検索インデックスの現在のステータスを判別するには、$listSearchIndexes
パイプライン ステージで集計操作を実行します。
次のコード例を ファイルにコピーします。
createSearchIndexes
次のサンプルアプリケーションでは、 コマンドを指定して検索インデックスを定義します。次に、アプリケーションはコマンドと検索インデックス情報をBSONに変換し、この情報を mongoc_collection_command_simple()
メソッドに渡して検索インデックスを作成します。詳細については、「 インデックス リファレンス 」を参照してください。
int main (void) { mongoc_client_t *client = NULL; mongoc_collection_t *collection = NULL; mongoc_database_t *database = NULL; bson_error_t error; bson_t cmd = BSON_INITIALIZER; bool ok = true; mongoc_init(); // Connect to your Atlas deployment client = mongoc_client_new("<connectionString>"); if (!client) { fprintf(stderr, "Failed to create a MongoDB client.\n"); ok = false; goto cleanup; } // Access your database and collection database = mongoc_client_get_database(client, "<databaseName>"); collection = mongoc_database_get_collection(database, "<collectionName>"); // Specify the command and the new index const char *cmd_str = BSON_STR({ "createSearchIndexes" : "<collectionName>", "indexes" : [ { "name" : "<indexName>", "definition" : { "analyzer": "<indexAnalyzer>", "searchAnalyzer": "<queryAnalyzer>", "mappings": { "dynamic": <boolean>, "fields": { <fieldDefinition> } }, "numPartitions": <integer>, "analyzers": [ <customAnalyzer> ], "storedSource": <boolean> | { <storedSourceDefinition> }, "synonyms": [ { <synonymMappingDefinition> } ] } } ] }); // Convert your command to BSON if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) { fprintf(stderr, "Failed to parse command: %s\n", error.message); ok = false; goto cleanup; } // Create the Atlas search index by running the command if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) { fprintf(stderr, "Failed to run createSearchIndexes: %s\n", error.message); ok = false; goto cleanup; } printf ("Index created!\n"); cleanup: mongoc_collection_destroy (collection); mongoc_client_destroy (client); mongoc_database_destroy (database); bson_destroy (&cmd); mongoc_cleanup (); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
createSearchIndexes
次のサンプルアプリケーションでは、 コマンドを使用して複数の検索インデックスを定義します。次に、アプリケーションはコマンドと検索インデックス情報をBSONに変換し、この情報を mongoc_collection_command_simple()
メソッドに渡して検索インデックスを作成します。詳細については、「 インデックス リファレンス 」を参照してください。
int main (void) { mongoc_client_t *client = NULL; mongoc_collection_t *collection = NULL; mongoc_database_t *database = NULL; bson_error_t error; bson_t cmd = BSON_INITIALIZER; bool ok = true; mongoc_init(); // Connect to your Atlas deployment client = mongoc_client_new("<connectionString>"); if (!client) { fprintf(stderr, "Failed to create a MongoDB client.\n"); ok = false; goto cleanup; } // Access your database and collection database = mongoc_client_get_database(client, "<databaseName>"); collection = mongoc_database_get_collection(database, "<collectionName>"); // Specify the command and the new indexes const char *cmd_str = BSON_STR({ "createSearchIndexes" : "<collectionName>", "indexes" : [{ // Add your search index definition fields here "name" : "<firstIndexName>" }, { // Add your search index definition fields here "name" : "<secondIndexName>" }] }); // Convert your command to BSON if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) { fprintf(stderr, "Failed to parse command: %s\n", error.message); ok = false; goto cleanup; } // Create the Atlas search indexes by running the command if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) { fprintf(stderr, "Failed to run createSearchIndexes: %s\n", error.message); ok = false; goto cleanup; } printf ("Indexes created!\n"); cleanup: mongoc_collection_destroy (collection); mongoc_client_destroy (client); mongoc_database_destroy (database); bson_destroy (&cmd); mongoc_cleanup (); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを作成するデータベースとコレクション。
インデックスの名前。インデックス名を省略すると、Atlas Search はインデックスに
default
という名前を付けます。検索インデックスの定義。詳細については、「 インデックス リファレンス 」を参照してください。
C++ ドライバーを使用して Atlas Search インデックスを作成するには、アプリケーションで検索インデックスを定義し、create_one()
メソッドを呼び出します。
注意
Atlas Search インデックスマネジメントのメソッドは非同期で実行されます。ドライバーメソッドは、正常に実行されたことを確認する前に戻ることができます。検索インデックスの現在の状態を確認するには、検索インデックスビューのインスタンスで list()
メソッドを呼び出します。
次のコード例を ファイルにコピーします。
次のサンプルアプリケーションでは、検索インデックスの名前と定義をsearch_index_model()
メソッドに渡して、コレクション内のフィールドに動的にインデックス。次に、アプリケーションは検索インデックスの仕様をcreate_one()
メソッドに渡して検索インデックスを作成します。詳細については、「 インデックス リファレンス 」を参照してください。
using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; using namespace mongocxx; int main() { try { // Connect to your Atlas deployment mongocxx::instance instance{}; mongocxx::uri uri("<connectionString>"); mongocxx::client client(uri); // Access your database and collection auto db = client["<databaseName>"]; auto collection = db["<collectionName>"]; // Create an index model with your index name and definition auto siv = collection.search_indexes(); auto name = "<indexName>"; auto definition = make_document(kvp("mappings", make_document(kvp("dynamic", true)))); auto model = search_index_model(name, definition.view()); // Create the search index siv.create_one(model); std::cout << "Index created!" << std::endl; } catch (const std::exception& e) { std::cout<< "Exception: " << e.what() << std::endl; } return 0; }
一度に複数の Atlas Search インデックスを作成することもできます。作成する検索インデックスごとに、検索インデックスの仕様を search_index_model()
メソッドに渡します。次に、各検索インデックスをベクトルに追加し、そのベクトルを create_many()
メソッドに渡して検索インデックスを作成します。
using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; using namespace mongocxx; int main() { try { // Connect to your Atlas deployment mongocxx::instance instance{}; mongocxx::uri uri("<connectionString>"); mongocxx::client client(uri); // Access your database and collection auto db = client["<databaseName>"]; auto collection = db["<collectionName>"]; // Create index models and add them to a vector auto siv = collection.search_indexes(); std::vector<search_index_model> models; auto name1 = "<firstIndexName>"; auto definition1 = make_document(/* Add search index definition fields here */); auto model1 = search_index_model(name1, definition1.view()); models.push_back(model1); auto name2 = "<secondIndexName>"; auto definition2 = make_document(/* Add search index definition fields here */); auto model2 = search_index_model(name2, definition2.view()); models.push_back(model2); // Create the search indexes siv.create_many(models); std::cout << "Indexes created!" << std::endl; } catch (const std::exception& e) { std::cout<< "Exception: " << e.what() << std::endl; } return 0; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを作成するデータベースとコレクション。
インデックスの名前。インデックス名を省略すると、Atlas Search はインデックスに
default
という名前を付けます。
検索インデックスの定義。詳細については、「 インデックス リファレンス 」を参照してください。
.NET/C# ドライバーを使用して MongoDB Atlas Search 検索インデックスを作成するには、次の手順を行います。
インデックスを定義する
BsonDocument
を構築します。BsonDocument
をCreateOne()
またはCreateOneAsync()
メソッドに渡します。
Program.cs
ファイルの内容を、インデックスを定義する BsonDocument
に置き換えます。
以下の例アプリケーション のプレースホルダー値を置き換えます。このアプリケーションでは、 SearchIndexes.CreateOne
コマンドを使用して Atlas Searchインデックスを定義します。
値 | 説明 |
---|---|
| Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。 |
| インデックスを作成するデータベース。 |
| インデックスを作成するコレクション。 |
| インデックスの名前。インデックス名を省略すると、Atlas Search はインデックスに |
| インデックスの定義 。インデックス定義の構文の詳細については、「 インデックス リファレンス 」を参照してください。 |
1 using MongoDB.Bson; 2 using MongoDB.Driver; 3 4 // connect to your Atlas deployment 5 var uri = "<connection-string>"; 6 7 var client = new MongoClient(uri); 8 9 var db = client.GetDatabase("<databaseName>"); 10 var collection = db.GetCollection<BsonDocument>("<collectionName>"); 11 12 // define your Atlas Search index 13 var index = new BsonDocument 14 { 15 { "mappings", new BsonDocument 16 { 17 { "dynamic", true } 18 } 19 } 20 }; 21 22 var result = collection.SearchIndexes.CreateOne(index, "<indexName>"); 23 Console.WriteLine(result);
以下の例アプリケーション のプレースホルダー値を置き換えます。このアプリケーションでは、 SearchIndexes.CreateMany
コマンドを使用して Atlas Searchインデックスを定義します。
値 | 説明 |
---|---|
| Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。 |
| インデックスを作成するデータベース。 |
| インデックスを作成するコレクション。 |
| 最初のインデックスの名前。 |
| 最後のインデックスの名前。 |
| インデックスの定義 。インデックス定義の構文の詳細については、「 インデックス リファレンス 」を参照してください。 |
1 using MongoDB.Bson; 2 using MongoDB.Driver; 3 4 // connect to your Atlas deployment 5 var uri = "<connection-string>"; 6 7 var client = new MongoClient(uri); 8 9 var db = client.GetDatabase("<databaseName>"); 10 var collection = db.GetCollection<BsonDocument>("<collectionName>"); 11 12 // define your Atlas Search indexes 13 var indexes = new List<CreateSearchIndexModel> 14 { 15 new CreateSearchIndexModel( 16 "<firstIndexName>", 17 new BsonDocument 18 { 19 <IndexDefinition>// search index definition fields 20 } 21 ), 22 ... 23 new CreateSearchIndexModel( 24 "<lastIndexName>", 25 new BsonDocument 26 { 27 <IndexDefinition> // search index definition fields 28 } 29 ) 30 }; 31 32 var result = collection.SearchIndexes.CreateMany(indexes);
Javaドライバー を使用して Atlas Searchインデックスを作成するには、検索インデックスを定義するドキュメントを作成し、そのドキュメントをcreateSearchIndex()
メソッドまたは createSearchIndexes()
メソッドに渡します。
注意
Atlas Search インデックス マネジメントのメソッドは非同期で実行されます。ドライバー メソッドは、正常に実行されたことを確認する前に戻ることができます。インデックスの現在のステータスを確認するには、listSearchIndexes()
メソッドを呼び出します。
次のコード例を ファイルにコピーします。
次のサンプルアプリケーションでは、コレクション内のフィールドに動的にインデックスための検索インデックスを定義し、createSearchIndex()
メソッドを実行してインデックスを作成します。詳細については、「 インデックス リファレンス 」を参照してください。
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; public class CreateIndex { public static void main(String[] args) { // connect to your Atlas cluster String uri = "<connection-string>"; try (MongoClient mongoClient = MongoClients.create(uri)) { // set namespace MongoDatabase database = mongoClient.getDatabase("<databaseName>"); MongoCollection<Document> collection = database.getCollection("<collectionName>"); Document index = new Document("mappings", new Document("dynamic", true)); collection.createSearchIndex("<index-name>", index); } } }
次のサンプルアプリケーションを使用して、一度に複数の Atlas Search インデックスを作成できます。そのためには、作成する検索インデックスごとにドキュメントを作成し、そのドキュメントを配列として createSearchIndexes()
メソッドに渡します。
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.SearchIndexModel; import org.bson.Document; import java.util.Arrays; public class CreateIndex { public static void main(String[] args) { // connect to your Atlas cluster String uri = "<connection-string>"; try (MongoClient mongoClient = MongoClients.create(uri)) { // set namespace MongoDatabase database = mongoClient.getDatabase("<databaseName>"); MongoCollection<Document> collection = database.getCollection("<collectionName>"); SearchIndexModel indexOne = new SearchIndexModel("<first-index-name>", new Document( // search index definition fields )); SearchIndexModel indexTwo = new SearchIndexModel("<second-index-name>", new Document( // search index definition fields )); collection.createSearchIndexes(Arrays.asList(indexOne, indexTwo)); } } }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを作成するデータベースとコレクション。
インデックスの名前。インデックス名を省略すると、Atlas Search はインデックスに
default
という名前を付けます。
検索インデックスを定義するフィールド。詳細については、「 インデックス リファレンス 」を参照してください。
ノード ドライバーを使用して Atlas Search インデックスを作成する方法
アプリケーションから検索インデックスを定義します。
createSearchIndex
またはcreateSearchIndexes
ヘルパー メソッドを実行します。
検索インデックスを定義します。
Atlas Searchインデックスの定義に createSearchIndex
コマンドを使用する create-index.js
という名前の次の例アプリケーションのプレースホルダー値を置き換えます。
値 | 説明 |
---|---|
| Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。 |
| インデックスを作成するデータベース。 |
| インデックスを作成するコレクション。 |
| インデックスの名前。 インデックス名を省略すると、Atlas Search はインデックスに |
| インデックスの定義 。インデックス定義の構文の詳細については、「 インデックス リファレンス 」を参照してください。 |
import { MongoClient } from "mongodb"; // connect to your Atlas deployment const uri = "<connectionString>"; const client = new MongoClient(uri); async function run() { try { const database = client.db("<databaseName>"); const collection = database.collection("<collectionName>"); // define your Atlas Search index const index = { name: "<indexName>", definition: { /* search index definition fields */ <indexDefinition> } } // run the helper method const result = await collection.createSearchIndex(index); console.log(result); } finally { await client.close(); } } run().catch(console.dir);
値 | 説明 |
---|---|
| Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。 |
| インデックスを作成するデータベース。 |
| インデックスを作成するコレクション。 |
| インデックスの名前。 インデックス名を省略すると、Atlas Search はインデックスに |
| インデックスの定義 。インデックス定義の構文の詳細については、「 インデックス リファレンス 」を参照してください。 |
Atlas Searchインデックスの定義に createSearchIndexes
コマンドを使用する create-index.js
という名前の次の例アプリケーションのプレースホルダー値を置き換えます。
import { MongoClient } from "mongodb"; // connect to your Atlas deployment const uri = "<connection-string>"; const client = new MongoClient(uri); async function run() { try { const database = client.db("<databaseName>"); const collection = database.collection("<collectionName>"); // define an array of Atlas Search indexes const indexes = [ { name: "<first-index-name>", definition: { /* search index definition fields */ } }, ... { name: "<last-index-name>", definition: { /* search index definition fields */ } } ] // run the helper method const result = await collection.createSearchIndexes(indexes); console.log(result); } finally { await client.close(); } } run().catch(console.dir);
Python ドライバーを使用して Atlas Search インデックスを作成するには、アプリケーションから検索インデックスを定義し、create_search_index()
メソッドを呼び出します。
注意
Atlas Search インデックス マネジメントのメソッドは非同期で実行されます。ドライバー メソッドは、正常に実行されたことを確認する前に戻ることができます。検索インデックスの現在のステータスを確認するには、コレクションで list_search_indexes()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプルアプリケーションでは、コレクション内のフィールドに動的にインデックス検索インデックスを定義します。次に、アプリケーションはコレクションのcreate_search_index()
メソッドを呼び出して検索インデックスを作成します。詳細については、「 インデックス リファレンス 」を参照してください。
from pymongo.mongo_client import MongoClient from pymongo.operations import SearchIndexModel def create_index(): # Connect to your Atlas deployment uri = "<connectionString>" client = MongoClient(uri) # Access your database and collection database = client["<databaseName>"] collection = database["<collectionName>"] # Create your index model, then create the search index search_index_model = SearchIndexModel( definition={ "mappings": { "dynamic": True }, }, name="<indexName>", ) result = collection.create_search_index(model=search_index_model) print(result)
一度に複数の Atlas Search インデックスを作成することもできます。アプリケーションで、検索インデックスの配列を定義します。そして、その配列を create_search_indexes()
メソッドのパラメーターとして渡します。
from pymongo.mongo_client import MongoClient from pymongo.operations import SearchIndexModel def create_indexes(): # Connect to your Atlas deployment uri = "<connectionString>" client = MongoClient(uri) # Access your database and collection database = client["<databaseName>"] collection = database["<collectionName>"] # Create your index models and add them to an array first_model = SearchIndexModel( definition={ # Add search index definition fields here }, name="<firstIndexName>", ) second_model = SearchIndexModel( definition={ # Add search index definition fields here }, name="<secondIndexName>", ) idx_models = [first_model, second_model] # Create the search indexes result = collection.create_search_indexes(models=idx_models) print(result)
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを作成するデータベースとコレクション。
インデックスの名前。インデックス名を省略すると、Atlas Search はインデックスに
default
という名前を付けます。
検索インデックスの定義。詳細については、「 インデックス リファレンス 」を参照してください。
Atlas Searchインデックスを作成 すると、Atlas Search ページには Atlas Search インデックスに関する情報が表示されます。Status 列には、クラスターのプライマリノードにおけるインデックスの現在の状態が表示されます。詳細については、「 インデックス ステータスの確認 」を参照してください。
警告
Atlas Search インデックスが既に存在するコレクションをシャーディングする場合、コレクションがシャードに表示され始めるときにクエリのダウンタイムが短時間発生することがあります。また、シャードを Atlas Search インデックスなどのシャーディングされたコレクションに追加する場合、追加されたシャードで最初の同期プロセスが完了するまで、そのコレクションに対する検索クエリは失敗します。詳しくは、「最初の同期プロセス」を参照してください。
Atlas Search インデックスの表示
➤ [ 言語を選択 ] ドロップダウン メニューを使用して、このセクションの手順の言語を設定します。
Atlas Search APIを使用して Atlas Searchインデックスを検索するには、次の手順に従います。
GET
リクエストを送信します。
取得する Atlas Search インデックスの一意の ID または名前を指定して、 GET
リクエストをsearch/indexes/
エンドポイントに送信します。
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --include \ --request GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{indexId}"
どちらのエンドポイントの構文とパラメータの詳細についても、「名前を1 つ取得 」および「 ID を使用して 1 つの取得 」を参照してください。
コレクションのすべての Atlas Search インデックスを取得するには:
GET
リクエストを送信します。
インデックスを取得するコレクションの名前を指定して、 search/indexes/
エンドポイントにGET
リクエストを送信します。
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --include \ --request GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{databaseName}/{collectionName}"
クラスターのすべての Atlas Search インデックスを取得するには:
GET
リクエストを送信します。
検索対象のインデックスを持つクラスターの名前を指定して、 search/indexes/
エンドポイントにGET
リクエストを送信します。
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --include \ --request GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes"
クラウド配置の Atlas Search インデックスの取得
Atlas CLI を使用してクラスターのすべての検索インデックスを一覧表示するには、次のコマンドを実行します。
atlas clusters search indexes list [options]
Atlas CLI を使用して、指定した検索インデックスの詳細を返すには、次のコマンドを実行します。
atlas clusters search indexes describe <indexId> [options]
前のコマンドの構文とパラメーターの詳細については、Atlas CLI ドキュメントのAtlas クラスター検索インデックス リストおよびAtlas クラスター検索インデックスの説明を参照してください。
ローカル配置の Atlas Search インデックスの取得
Atlas CLI を使用して指定した配置の指定された検索インデックスを記述するには、次のコマンドを実行します。
atlas deployments search indexes describe [indexId] [options]
Atlas CLI を使用して、指定したデプロイのすべての検索インデックスを一覧表示するには、次のコマンドを実行します。
atlas deployments search indexes list [options]
前のコマンドの構文とパラメータの詳細については、Atlas CLI ドキュメントの「Atlas配置Atlas Searchインデックスの説明」および「Atlas配置Atlas Searchインデックス リスト」を参照してください。
Atlas UI Atlas Search ページを表示するには:
AtlasGoClustersAtlas で、プロジェクトの ページにGoします。
警告
ナビゲーションの改善が進行中
現在、新しく改善されたナビゲーション エクスペリエンスを展開しています。次の手順が Atlas UIのビューと一致しない場合は、プレビュー ドキュメントを参照してください。
まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー
まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。
まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。
[ Clusters (クラスター) ] ページが表示されます。
Atlas Search ページには、プロジェクト内の既存の Atlas Search インデックスのそれぞれを次の列で説明するテーブルが含まれています。
コラム | 説明 |
---|---|
Database | コレクションを含むデータベースの名前。 |
Collection | インデックス作成されたコレクションの名前。 |
Index Name | インデックスの名前。 |
Status | クラスターのプライマリノード上のインデックスのステータス。詳細については、「 Atlas Search インデックスのステータス 」を参照してください。 |
Queryable | インデックスを使用してコレクションがクエリできるかどうかを識別するアイコン。値は次のいずれかのアイコンにすることができます。
|
Type | インデックスのタイプ。値は、次のいずれかのタイプのインデックスです。
|
Index Fields | |
Documents | クラスタ上のプライマリノードまたは検索ノードでのインデックス構築中および構築後の、コレクション内のドキュメント総数に占めるインデックス作成されたドキュメントのおおよその数と割合。 |
Size | インデックスのサイズ。 |
Actions | インデックスに対して実行できるアクション:
|
デフォルトでは 、Atlas は最初にデータベース名でインデックスをソートし、次にコレクション名でソートします。複数の列で並べ替えるには、Shift
を押し、インデックスのリストを複数並べ替える順序で列名をクリックします。
この表から、各インデックスの詳細については、次のセクションに移動してください。
Index Overview
Atlas Search ページから Index Overview ページに移動するには、Index Name 列に表示するインデックスの名前をクリックします。各インデックスについて、Index Overview ページにはインデックスの名前空間と、インデックス定義で指定された次の構成が表示されます。
行 | 説明 |
---|---|
インデックスアナライザ | 検索インデックスを構築するときに、テキストを処理し、トークン化する方法を指定する テキストアナライザを選択しました。 |
searchAnalyzer | 検索クエリ内のテキストを処理およびトークン化する方法を指定するテキストアナライザを選択します。 |
ダイナミックマッピング | フィールドマッピングで動的マッピングまたは静的マッピングを有効にしたかどうかを示すブール値 |
フィールド マッピング | 指定されたフィールドマッピング(フィールド名、データ型、個々のフィールドで 動的マッピング が有効になっているかどうかなど) |
保存済みソース フィールド | 保存されているソース フィールド |
同義語マッピング |
mongosh
を通じて Atlas Search インデックスを検索するには、 db.collection.getSearchIndexes()
メソッドを使用します。
このコマンドの構文は、次のとおりです。 インデックス名を省略すると、Atlas Search はコレクションのすべてのインデックスを返します。
db.<collection>.getSearchIndexes("<index-name>")
例
次のコマンドは、 movies
コレクションからdefault
という名前の検索インデックスを検索します。 結果は出力例のようになります。
db.movies.getSearchIndexes("default")
[ { id: '648b4ad4d697b73bf9d2e5e0', name: 'default', status: 'READY', queryable: true, latestDefinition: { mappings: { dynamic: true } } } ]
MongoDB Compass経由で Atlas クラスターに接続します。
Compass を開き、Atlas クラスターに接続します。詳しくは、「 Compass 経由で接続 」を参照してください。
Indexesタブをクリックし、Search Indexes をクリックします。
ページには、次の情報が表示されます。
列名 | 説明 |
---|---|
Name and Fields | インデックスの名前と、インデックス付きフィールドの名前。 |
Type | インデックスのタイプ 。値は |
Status | インデックスのステータス 。詳細については、「インデックス ステータスの確認」を参照してください。 |
アクション | インデックスにカーソルを合わせると、インデックスに対して実行できるアクションが実行できます。次のアクションを実行できます。
|
C ドライバーを使用して Atlas Search インデックスを取得するには、 mongoc_collection_aggregate()
メソッドを使用して、 $listSearchIndexes
ステージを含む集計パイプラインを作成します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、 集計パイプライン の$listSearchIndexes
ステージを指定します。 次に、アプリケーションはパイプラインとターゲット コレクションをmongoc_collection_aggregate()
メソッドに渡します。 このメソッドは、コードが各 Atlas Search インデックスにアクセスして出力するカーソルを返します。
int main (void) { mongoc_client_t *client = NULL; mongoc_collection_t *collection = NULL; mongoc_database_t *database = NULL; bson_error_t error; bson_t cmd = BSON_INITIALIZER; bool ok = true; bson_t pipeline = BSON_INITIALIZER; mongoc_cursor_t *cursor = NULL; mongoc_init(); // Connect to your Atlas deployment client = mongoc_client_new("<connectionString>"); if (!client) { fprintf(stderr, "Failed to create a MongoDB client.\n"); ok = false; goto cleanup; } // Access your database and collection database = mongoc_client_get_database(client, "<databaseName>"); collection = mongoc_database_get_collection(database, "<collectionName>"); // Create an aggregation pipeline with the $listSearchIndexes stage const char *pipeline_str = BSON_STR ({"pipeline" : [ {"$listSearchIndexes" : {}} ]}); // Convert your aggregation pipeline to BSON if (!bson_init_from_json(&pipeline, pipeline_str, -1, &error)) { fprintf(stderr, "Failed to parse command: %s\n", error.message); ok = false; goto cleanup; } // Run the aggregation operation and iterate through the indexes returned cursor = mongoc_collection_aggregate (collection, MONGOC_QUERY_NONE, &pipeline, NULL, NULL); const bson_t *got; char *str; while (mongoc_cursor_next (cursor, &got)) { str = bson_as_canonical_extended_json (got, NULL); printf ("%s\n", str); bson_free (str); } if (mongoc_cursor_error (cursor, &error)) { fprintf (stderr, "Failed to iterate all documents: %s\n", error.message); ok = false; goto cleanup; } cleanup: mongoc_cursor_destroy(cursor); mongoc_collection_destroy(collection); mongoc_database_destroy(database); mongoc_client_destroy(client); bson_destroy(&pipeline); bson_destroy(&cmd); mongoc_cleanup (); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを取得するデータベースとコレクション。
C++ ドライバーを使用して Atlas Search インデックスを取得するには、検索インデックス ビューでlist()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、ターゲット コレクションのsearch_indexes()
メソッドを使用して検索インデックス ビューをインスタンス化します。 次に、アプリケーションはビューでlist()
メソッドを呼び出します。 このメソッドは、コードが各 Atlas Search インデックスにアクセスして出力するカーソルを返します。
using namespace mongocxx; int main() { mongocxx::instance instance{}; try { // Connect to your Atlas deployment mongocxx::uri uri("<connectionString>"); mongocxx::client client(uri); // Access your database and collection auto db = client["<databaseName>"]; auto collection = db["<collectionName>"]; // Access and print the indexes in your collection auto siv = collection.search_indexes(); auto cursor = siv.list(); for (auto&& doc : cursor) { std::cout << bsoncxx::to_json(doc) << std::endl; }; } catch (const std::exception& e) { std::cout<< "Exception: " << e.what() << std::endl; } return 0; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを取得するデータベースとコレクション。
.NET/C# ドライバー を使用して Atlas Search インデックスを取得するには、 メソッドまたはList()
ListAsync()
メソッドを使用します。
例
次のサンプル アプリケーションは、 コレクションのインデックスを返します。 次の値を指定します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
検索対象の検索インデックスを含むデータベースとコレクション。
注意
List()
メソッドは、インデックス自体ではなくカーソルを返します。 インデックスにアクセスするには、 MoveNext()
メソッドなどのカーソル パラダイムを使用します。
using MongoDB.Bson; using MongoDB.Driver; // connect to your Atlas deployment var uri = "<connection-string>"; var client = new MongoClient(uri); var db = client.GetDatabase("<databaseName>"); var collection = db.GetCollection<BsonDocument>("<collectionName>"); // list your Atlas Search indexes var result = collection.SearchIndexes.List().ToList(); foreach (var index in result) { Console.WriteLine(index); }
サンプル アプリケーションを実行するには、csharp-list-indexes
という名前の新しい .NET コンソール プロジェクトを作成し、前のサンプル コードを Program.cs
ファイルにコピーします。次に、以下のコマンドを使ってプロジェクトを実行します。
dotnet run csharp-list-indexes.csproj
<indexes for this collection>
Java ドライバーを使用してコレクションの Atlas Search インデックスを検索するには、 listSearchIndexes()
メソッドを使用します。 Java ドライバーv 4.11.0以上が必要です。
次のコード例を ファイルにコピーします。
次のサンプルアプリケーションは、特定のコレクションのすべての Atlas Search インデックスを検索します。
1 import com.mongodb.client.MongoClient; 2 import com.mongodb.client.MongoClients; 3 import com.mongodb.client.MongoCollection; 4 import com.mongodb.client.MongoCursor; 5 import com.mongodb.client.MongoDatabase; 6 import org.bson.Document; 7 public class ViewIndex { 8 public static void main(String[] args) { 9 // connect to your Atlas cluster 10 String uri = "<connection-string>"; 11 try (MongoClient mongoClient = MongoClients.create(uri)) { 12 // set namespace 13 MongoDatabase database = mongoClient.getDatabase("<database-name>"); 14 MongoCollection<Document> collection = database.getCollection("<collection-name>"); 15 // retrieve indexes 16 try (MongoCursor<Document> resultsCursor = collection.listSearchIndexes().iterator()) { 17 while (resultsCursor.hasNext()) { 18 System.out.println(resultsCursor.next()); 19 } 20 } 21 } 22 } 23 }
以下の値を置き換えて、ファイルを保存します。
<connection-string>
- Atlas接続文字列。 詳しくは、「ドライバーによる接続 」を参照してください。<database-name>
- コレクションを含むデータベースの名前。<collection-name>
- インデックスを検索するコレクションの名前。
以下も参照してください。
Node Driverを通じて Atlas Search インデックスを検索するには、 listSearchIndexes
ヘルパー メソッドを使用します。
例
コレクションのインデックスを返すには、 list-indexes.js
という名前の次のサンプル アプリケーションを使用します。 次の値を指定します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
検索対象の検索インデックスを含むデータベースとコレクション。
特定のインデックスを検索する場合は、インデックス名。 コレクションのすべてのインデックスを返すには、この値を省略します。
注意
listSearchIndexes
コマンドはカーソルを返します。 その結果、 コマンドに一致するインデックスはすぐに返されません。 結果にアクセスするには、 toArray()
メソッドなどのカーソル パラダイムを使用します。 詳細については、「カーソルからデータにアクセスする 」を参照してください。
import { MongoClient } from "mongodb"; // connect to your Atlas deployment const uri = "<connection-string>"; const client = new MongoClient(uri); async function run() { try { const database = client.db("<databaseName>"); const collection = database.collection("<collectionName>"); // run the helper method const result = await collection.listSearchIndexes("<index-name>").toArray(); console.log(result); } finally { await client.close(); } } run().catch(console.dir);
サンプル アプリケーションを実行するには、次のコマンドを使用します。 結果は出力例のようになります。
node list-indexes.js
[ { id: '648b4ad4d697b73bf9d2e5e0', name: 'default', status: 'READY', queryable: true, latestDefinition: { mappings: { dynamic: true } } }, { id: '648b4ad4d697b73bf9d2e5e1', name: 'example-index', status: 'PENDING', queryable: false, latestDefinition: { mappings: { dynamic: false, fields: { text: { type: 'string' } } } } } ]
Python ドライバーを使用して Atlas Search インデックスを取得するには、コレクションでlist_search_indexes()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、コレクションでlist_search_indexes()
メソッドを呼び出します。 このメソッドは、コードが各 Atlas Search インデックスにアクセスして出力するカーソルを返します。
from pymongo.mongo_client import MongoClient def view_index(): # Connect to your Atlas deployment uri = "<connectionString>" client = MongoClient(uri) # Access your database and collection database = client["<databaseName>"] collection = database["<collectionName>"] # Get a list of the collection's search indexes and print them cursor = collection.list_search_indexes() for index in cursor: print(index)
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを取得するデータベースとコレクション。
Atlas Search インデックス ドラフトの再開または削除
Atlas UIで下書きとして保存したインデックス定義を再開または削除するには、
重要
保留中のインデックス ドラフトがある場合は、インデックスを新規作成できません。
AtlasGoClustersAtlas で、プロジェクトの ページにGoします。
警告
ナビゲーションの改善が進行中
現在、新しく改善されたナビゲーション エクスペリエンスを展開しています。次の手順が Atlas UIのビューと一致しない場合は、プレビュー ドキュメントを参照してください。
まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー
まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。
まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。
[ Clusters (クラスター) ] ページが表示されます。
Atlas Search インデックスの編集
既存の Atlas Search インデックスのインデックス定義を変更できます。 インデックスの名前は変更できません。インデックスの名前を変更する必要がある場合は、新しいインデックスを作成し、古いインデックスを削除する必要があります。
Atlas Searchインデックスは、 Atlas UIを使用するか、mongosh
、 Atlas CLI、API、または希望言語でサポートされているMongoDBドライバーを使用して、プログラムによって編集できます。
➤ [ 言語を選択 ] ドロップダウン メニューを使用して、このセクションの手順の言語を設定します。
APIを通じて Atlas Search インデックスを編集するには、次の手順に従います。
PATCH
リクエストを送信します。
変更する Atlas Search インデックスの一意の ID または名前を指定して、 PATCH
リクエストをsearch/indexes/
エンドポイントに送信します。
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --include \ --request PATCH "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{indexId}" \ --data ' { "definition": { "analyzer": "lucene.<analyzer>", "analyzers": [ { "charFilters": [ ... ], "name": "string", "tokenFilters": [ ... ], "tokenizer": { ... } } ], "mappings": { "dynamic": true | false, "fields": { "property1": {}, ... } }, "searchAnalyzer": "<analyzer-name>", "storedSource": { "include | exclude": [...] }, "synonyms": [ { <synonym-mapping-definition> } } ] } }'
どちらのエンドポイントの構文とパラメータの詳細についても、「名前を使用して1 つの更新 」および「 ID を使用して 1 つの更新 」を参照してください。
Atlas CLI を使用してクラスターの検索インデックスを更新するには、次のコマンドを実行します。
atlas clusters search indexes update <indexId> [options]
コマンド構文とパラメーターについて詳しくは、「Atlas クラスター検索インデックス更新」の Atlas CLI ドキュメントを参照してください。
AtlasGoClustersAtlas で、プロジェクトの ページにGoします。
警告
ナビゲーションの改善が進行中
現在、新しく改善されたナビゲーション エクスペリエンスを展開しています。次の手順が Atlas UIのビューと一致しない場合は、プレビュー ドキュメントを参照してください。
まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー
まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。
まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。
[ Clusters (クラスター) ] ページが表示されます。
現在の構成設定を確認し、必要に応じて編集します。
次のインデックス構成設定を確認します。
ビジュアル エディター フィールド | 説明 | 必要性 |
---|---|---|
Index Analyzer | 任意 | |
Search Analyzer | 任意 | |
Dynamic Mapping | フィールドの動的マッピングまたは静的マッピングを指定します。 デフォルトでは 、動的マッピングは有効になっています。動的マッピングを無効にするには、 動的マッピングと静的マッピングについて詳しくは、「 フィールドマッピングの定義 」を参照してください。
| 必須 |
次の詳細構成設定を確認します。
フィールド名 | 説明 | 必要性 |
---|---|---|
Field Mappings | Index Configurations セクションの Dynamic Mapping が無効になっている場合は必須です。 インデックスを作成するフィールドを指定します。
フィールドマッピングの定義の詳細については、「 インデックス リファレンス 」を参照してください。
| 条件付き |
Stored Source Fields | クエリ時間検索用に Atlas Search に保存するフィールドを指定します。サポートされているすべての データ型 のフィールドを Atlas Search に保存できます。 フィールドの保存の詳細については、「Atlas Search インデックスに保存されたソース フィールドの定義」を参照してください。
| 任意 |
Synonyms Mappings | インデックスで使用する シノニム マッピング を指定します。 シノニム(同意語)マッピング を使用して、 同じアナライザで分析されたフィールドのみをクエリできます。 シノニム マッピングの詳細については、「 Atlas Search インデックスでのシノニム マッピングの定義 」を参照してください。
| 任意。 |
Index Partitions | フィールドオブジェクトが 2.1 00 億を超える場合に使用するパーティションの数。
| 任意。 |
次のインデックス構成設定を確認します。
フィールド名 | 説明 | 必要性 |
---|---|---|
| 任意 | |
| 任意 | |
| フィールドの動的マッピングまたは静的マッピングを指定します。動的マッピングを無効にするには、 | 必須 |
次の詳細構成設定を確認します。
フィールド名 | 説明 | 必要性 |
---|---|---|
|
インデックスを作成するフィールドを指定します。詳しくは「フィールドマッピングの定義」を参照してください。 | 条件付き |
| クエリ時間検索用に Atlas Search に保存するフィールドを指定します。サポートされているすべての データ型 のフィールドを Atlas Search に保存できます。 フィールドの保存の詳細については、「Atlas Search インデックスに保存されたソース フィールドの定義」を参照してください。 | 任意 |
| インデックスで使用する シノニム マッピング を指定します。 シノニム(同意語)マッピング を使用して、 同じアナライザで分析されたフィールドのみをクエリできます。 シノニム マッピングの詳細については、「 Atlas Search インデックスでのシノニム マッピングの定義 」を参照してください。 | 任意 |
| フィールドオブジェクトが 2.1 00 億を超える場合に使用するパーティションの数。 | 任意。 |
これらのインデックス定義設定の詳細については、「 インデックス リファレンス 」を参照してください。
mongosh
を通じて Atlas Search インデックスを編集するには、 db.collection.updateSearchIndex()
メソッドを使用します。
コマンドの構文は です。編集するインデックスの名前を指定し、新しいインデックス定義を定義します。この定義は、インデックスの既存の定義を置き換えます。詳細については、「 インデックス リファレンス 」を参照してください。
db.<collection>.updateSearchIndex( "<index-name>", /* updated search index definition */ )
例
次のコマンドは、静的マッピングを使用するように、 movies
コレクションからdefault
という名前の検索インデックスを更新します。
db.movies.updateSearchIndex( "default", { "mappings": { "dynamic": false, "fields": { "<field-name>": { "type": "<field-type>" } } } )
注意
db.collection.updateSearchIndex()
コマンドは出力を返しません。 Atlas UIを使用してインデックスのステータスを表示できます。
C ドライバーを使用して Atlas Search インデックスを編集するには、アプリケーション内の更新されたインデックス情報を指定し、 mongoc_collection_command_simple()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、 updateSearchIndex
コマンド、更新されたインデックス定義、既存のインデックス名を指定します。 次に、アプリケーションはコマンドと更新されたインデックス情報をBSONに変換し、この情報をmongoc_collection_command_simple()
メソッドに渡して検索インデックスを編集します。
int main (void) { mongoc_client_t *client = NULL; mongoc_collection_t *collection = NULL; mongoc_database_t *database = NULL; bson_error_t error; bson_t cmd = BSON_INITIALIZER; bool ok = true; mongoc_init(); // Connect to your Atlas deployment client = mongoc_client_new("<connectionString>"); if (!client) { fprintf(stderr, "Failed to create a MongoDB client.\n"); ok = false; goto cleanup; } // Access your database and collection database = mongoc_client_get_database(client, "<databaseName>"); collection = mongoc_database_get_collection(database, "<collectionName>"); // Specify the command and the updated index definition const char *cmd_str = BSON_STR({ "updateSearchIndex" : "<collectionName>", "definition" : {"mappings" : {"dynamic" : true}}, "name" : "<indexName>" }); // Convert your command to BSON if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) { fprintf(stderr, "Failed to parse command: %s\n", error.message); ok = false; goto cleanup; } // Update the Atlas search index by running the command if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) { fprintf(stderr, "Failed to run updateSearchIndex: %s\n", error.message); ok = false; goto cleanup; } printf ("Index updated!\n"); cleanup: mongoc_collection_destroy (collection); mongoc_database_destroy (database); mongoc_client_destroy (client); bson_destroy (&cmd); mongoc_cleanup (); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを更新するデータベースとコレクション。
更新するインデックスの名前。
検索インデックスを再定義するフィールド。詳細については、「 インデックス リファレンス 」を参照してください。
C++ ドライバーを使用して Atlas Search インデックスを編集するには、検索インデックス ビューでupdate_one()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプルアプリケーションでは、検索インデックスビューをインスタンス化し、新しいAtlas Search インデックス定義を指定します。 次に、アプリケーションはこの定義と既存のインデックス名をupdate_one()
メソッドに渡します。これにより、新しい定義ドキュメントを反映するように既存のインデックスがアップデートされます。
using namespace mongocxx; using bsoncxx::builder::basic::make_document; int main() { mongocxx::instance instance{}; try { // Connect to your Atlas deployment mongocxx::uri uri("<connectionString>"); mongocxx::client client(uri); // Access your database and collection auto db = client["<databaseName>"]; auto collection = db["<collectionName>"]; // Access the indexes in your collection auto siv = collection.search_indexes(); // Specify a new definiton and update your search index auto newDefinition = make_document(kvp("mappings", make_document(kvp("dynamic", true)))); siv.update_one("<indexName>", newDefinition.view()); } catch (const std::exception& e) { std::cout<< "Exception: " << e.what() << std::endl; } return 0; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを更新するデータベースとコレクション。
更新するインデックスの名前。
検索インデックスを再定義するフィールド。詳細については、「 インデックス リファレンス 」を参照してください。
.NET/C# ドライバー を使用して Atlas Search インデックスを編集するには、 メソッドまたはUpdate()
UpdateAsync()
メソッドを使用します。
例
次のサンプルアプリケーションでは、既存のインデックス定義をアップデートします。 次の値を指定します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
検索インデックスを作成したデータベースとコレクション。
既存の定義を置き換える新しいインデックス定義。この例では、静的マッピングを使用するようにインデックスを更新しています。この定義は、特定のインデックス ニーズに合わせて変更できます。詳細については、「 インデックス リファレンス 」を参照してください。
更新するインデックスの名前。
using MongoDB.Bson; using MongoDB.Driver; // connect to your Atlas deployment var uri = "<connection-string>"; var client = new MongoClient(uri); var db = client.GetDatabase("<databaseName>"); var collection = db.GetCollection<BsonDocument>("<collectionName>"); // define your Atlas Search index var index = new BsonDocument { // updated search index definition { "mappings", new BsonDocument { { "dynamic", false }, { "fields", new BsonDocument { { "<field-name>", new BsonDocument { { "type", "<field-type>" } } } } } } } }; collection.SearchIndexes.Update("<index-name>", index);
サンプル アプリケーションを実行するには、csharp-update-index
という名前の新しい .NET コンソール プロジェクトを作成し、前のサンプル コードを Program.cs
ファイルにコピーします。次に、以下のコマンドを使ってプロジェクトを実行します。
dotnet run csharp-update-index.csproj
注意
Update()
メソッドは出力を返しません。 Atlas UIを使用してインデックスのステータスを表示できます。
Java ドライバーを使用してコレクションの Atlas Search インデックスを編集するには、検索インデックス設定を変更するドキュメントを作成し、そのドキュメントをupdateSearchIndex()
メソッドに渡します。 Java ドライバーv 4.11.0以上が必要です。
次のコード例を ファイルにコピーします。
1 import com.mongodb.client.MongoClient; 2 import com.mongodb.client.MongoClients; 3 import com.mongodb.client.MongoCollection; 4 import com.mongodb.client.MongoDatabase; 5 import org.bson.Document; 6 7 public class EditIndex { 8 public static void main(String[] args) { 9 // connect to your Atlas cluster 10 String uri = "<connection-string>"; 11 12 try (MongoClient mongoClient = MongoClients.create(uri)) { 13 // set namespace 14 MongoDatabase database = mongoClient.getDatabase("<document-name>"); 15 MongoCollection<Document> collection = database.getCollection("<collection-name>"); 16 // define field mappings 17 Document index = new Document("analyzer", "<analyzer-name>").append( 18 "mappings", new Document("dynamic", <true|false>) 19 .append("fields", new Document("<field-name>", 20 new Document("type", "<field-type>")))); 21 // run the updateSearchIndex() method 22 collection.updateSearchIndex("<index-name>", index); 23 } 24 } 25 }
コード内の次の値を置き換え、ファイルを保存します。
<connection-string>
- Atlas接続文字列。 詳しくは、「ドライバーによる接続 」を参照してください。注意
接続文字列には、 writeConcern設定を含めないでください。
<database-name>
- コレクションを含むデータベースの名前。<collection-name>
- インデックスを検索するコレクションの名前。<analyzer-name>
-アナライザの名前。dynamic
- フィールドを自動的にインデックス化するかどうかを示すフラグ。<field-name>
- インデックスを作成するフィールドの名前。<field-type>
- フィールドのデータ型。<index-name>
- インデックスの名前。
ファイルをコンパイルして実行します。
javac EditIndex.java java EditIndex
updateSearchIndex()
メソッドは非同期で実行されます。listSearchIndexes()
メソッドを使用して、変更がインデックスに適用されたかどうかを判断します。 Atlas Search インデックスの取得の詳細については、「 Atlas Search インデックスの表示 」を参照してください。
以下も参照してください。
Node Driverを通じて Atlas Search インデックスを編集するには、 updateSearchIndex
ヘルパー メソッドを使用します。
例
既存のインデックス定義を更新するには、 update-index.js
という名前の次のサンプル アプリケーションを使用します。 次の値を指定します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
検索インデックスを作成したデータベースとコレクション。
既存の定義を置き換える新しいインデックス定義。この例では、静的マッピングを使用するようにインデックスを更新しています。この定義は、特定のインデックス ニーズに合わせて変更できます。詳細については、「 インデックス リファレンス 」を参照してください。
更新するインデックスの名前。
import { MongoClient } from "mongodb"; // connect to your Atlas deployment const uri = "<connection-string>"; const client = new MongoClient(uri); async function run() { try { const database = client.db("<databaseName>"); const collection = database.collection("<collectionName>"); // define your Atlas Search index const index = { /* updated search index definition */ "mappings": { "dynamic": false, "fields": { "<field-name>": { "type": "<field-type>" } } } } // run the helper method await collection.updateSearchIndex("<index-name>", index); } finally { await client.close(); } } run().catch(console.dir);
サンプル アプリケーションを実行するには、次のコマンドを使用します。
node update-index.js
注意
updateSearchIndex
メソッドは出力を返しません。 Atlas UIを使用してインデックスのステータスを表示できます。
Python ドライバーを使用して Atlas Search インデックスを更新するには、コレクションでupdate_search_index()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、新しい Atlas Search インデックス定義を指定します。 次に、アプリケーションはこの定義と既存のインデックス名をupdate_search_index()
メソッドに渡します。これにより、新しい定義ドキュメントを反映するように既存のインデックスがアップデートされます。
from pymongo.mongo_client import MongoClient def edit_index(): # Connect to your Atlas deployment uri = "<connectionString>" client = MongoClient(uri) # Access your database and collection database = client["<databaseName>"] collection = database["<collectionName>"] # Specify a new index definition definition = { "mappings": { "dynamic": True }, } # Update your search index collection.update_search_index("<indexName>", definition)
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを更新するデータベースとコレクション。
更新するインデックスの名前。
検索インデックスを再定義するフィールド。詳細については、「 インデックス リファレンス 」を参照してください。
注意
更新されたインデックスを作成する間、さまざまなノードがさまざまな速度で更新する可能性があります。この期間中に、新しいインデックス定義と以前のインデックス定義の両方を反映して、混合状態のクエリ結果が発生する場合があります。クエリを処理しているインデックスは、インデックスステータスの詳細ページで表示できます。
既存のインデックスの更新
一部の Atlas Search 機能では、インデックスを更新する必要があります。 インデックスを更新するには、次のいずれかのアクションを実行します。
Atlas Search インデックスの編集 の手順を使用してインデックス定義を編集します。
Atlas UIからインデックスの更新をオプトインするには、次の手順を実行します。
重要
Atlas Search インデックスの更新プロセスには時間とリソースが必要です。 インデックスの更新を正常に完了するには、現在のインデックスのディスク容量の125 % と等しい空きディスク容量を割り当てます。
AtlasGoClustersAtlas で、プロジェクトの ページにGoします。
警告
ナビゲーションの改善が進行中
現在、新しく改善されたナビゲーション エクスペリエンスを展開しています。次の手順が Atlas UIのビューと一致しない場合は、プレビュー ドキュメントを参照してください。
まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー
まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。
まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。
[ Clusters (クラスター) ] ページが表示されます。
Atlas Search インデックスの削除
Atlas Searchインデックスは、 Atlas UIまたは、mongosh
、 Atlas CLI、API、または希望言語でサポートされているMongoDBドライバーを使用して、プログラムによって削除できます。
➤ [ 言語を選択 ] ドロップダウン メニューを使用して、このセクションの手順の言語を設定します。
APIを使用して Atlas Search インデックスを削除するには、次の手順に従います。
DELETE
リクエストを送信します。
削除する Atlas Search インデックスの一意の ID または名前を指定して、 DELETE
リクエストをsearch/indexes/
エンドポイントに送信します。
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --include \ --request DELETE "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{indexId}"
どちらのエンドポイントの構文とパラメータの詳細についても、「名前を1 つ削除 」および「 ID を使用して 1 つの削除 」を参照してください。
クラウド配置用 Atlas Search インデックスの削除
Atlas CLI を使用してクラスターから検索インデックスを削除するには、次のコマンドを実行します。
atlas clusters search indexes delete <indexId> [options]
コマンド構文とパラメーターについて詳しくは、「Atlasクラスター検索インデックスの削除」の Atlas CLIドキュメントを参照してください。
ローカル配置の Atlas Search インデックスの削除
Atlas CLI を使用して指定したデプロイの指定した検索インデックスを削除するには、次のコマンドを実行します。
atlas deployments search indexes delete <indexId> [options]
コマンド構文とパラメーターの詳細については、Atlas CLI ドキュメントの「atlas deployments search indexes delete」を参照してください。
AtlasGoClustersAtlas で、プロジェクトの ページにGoします。
警告
ナビゲーションの改善が進行中
現在、新しく改善されたナビゲーション エクスペリエンスを展開しています。次の手順が Atlas UIのビューと一致しない場合は、プレビュー ドキュメントを参照してください。
まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー
まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。
まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。
[ Clusters (クラスター) ] ページが表示されます。
mongosh
を通じて Atlas Search インデックスを削除するには、 db.collection.dropSearchIndex()
メソッドを使用します。
このコマンドの構文は、次のとおりです。
db.<collection>.dropSearchIndex("<index-name>")
例
次のコマンドは、 movies
コレクションからdefault
という名前の検索インデックスを削除します。
db.movies.dropSearchIndex("default")
注意
db.collection.dropSearchIndex()
コマンドは出力を返しません。 Atlas UIを使用してインデックスのステータスを表示できます。
C ドライバーを使用して Atlas Search インデックスを削除するには、コレクションと drop コマンドをmongoc_collection_command_simple()
メソッドに渡します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、 dropSearchIndex
コマンドと既存のインデックス名を指定します。 次に、アプリケーションはコマンドとインデックス情報をBSONに変換し、この情報をmongoc_collection_command_simple()
メソッドに渡して検索インデックスを削除します。
int main (void) { mongoc_client_t *client = NULL; mongoc_collection_t *collection = NULL; mongoc_database_t *database = NULL; bson_error_t error; bson_t cmd = BSON_INITIALIZER; bool ok = true; mongoc_init(); // Connect to your Atlas deployment client = mongoc_client_new("<connectionString>"); if (!client) { fprintf(stderr, "Failed to create a MongoDB client.\n"); ok = false; goto cleanup; } // Access your database and collection database = mongoc_client_get_database(client, "<databaseName>"); collection = mongoc_database_get_collection(database, "<collectionName>"); // Specify the command and the index name const char *cmd_str = BSON_STR ({"dropSearchIndex" : "<collectionName>", "name" : "<indexName>"}); // Convert your command to BSON if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) { fprintf(stderr, "Failed to parse command: %s\n", error.message); ok = false; goto cleanup; } // Run the command to drop the search index if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) { fprintf(stderr, "Failed to run dropSearchIndex: %s\n", error.message); ok = false; goto cleanup; } printf ("Index dropped!\n"); cleanup: mongoc_collection_destroy(collection); mongoc_database_destroy(database); mongoc_client_destroy(client); bson_destroy(&cmd); mongoc_cleanup (); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを削除するデータベースとコレクション。
削除するインデックスの名前。
C++ ドライバーを使用して Atlas Search インデックスを削除するには、検索インデックス ビューでdrop_one()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、ターゲット コレクションのsearch_indexes()
メソッドを使用して検索インデックス ビューをインスタンス化します。 次に、アプリケーションはビューでdrop_one()
メソッドを呼び出し、インデックスを削除するためのパラメーターとして Atlas Search インデックス名を渡します。
using namespace mongocxx; int main() { mongocxx::instance instance{}; try { // Connect to your Atlas deployment mongocxx::uri uri("<connectionString>"); mongocxx::client client(uri); // Access your database and collection auto db = client["<databaseName>"]; auto collection = db["<collectionName>"]; // Access the indexes in your collection auto siv = collection.search_indexes(); // Delete your search index auto name = "<indexName>"; siv.drop_one(name); } catch (const std::exception& e) { std::cout<< "Exception: " << e.what() << std::endl; } return 0; }
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを取得するデータベースとコレクション。
削除するインデックスの名前。
.NET/C# ドライバー を使用して Atlas Search インデックスを削除するには、 メソッドまたはDropOne()
DropOneAsync()
メソッドを使用します。
例
次のサンプル アプリケーションは、コレクションからインデックスを削除します。 次の値を指定します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
削除する検索インデックスを含むデータベースとコレクション。
削除する検索インデックスの名前。
using MongoDB.Bson; using MongoDB.Driver; // connect to your Atlas deployment var uri = "<connection-string>"; var client = new MongoClient(uri); var db = client.GetDatabase("<databaseName>"); var collection = db.GetCollection<BsonDocument>("<collectionName>"); // drop your Atlas Search index collection.SearchIndexes.DropOne("<index name>");
サンプル アプリケーションを実行するには、csharp-delete-index
という名前の新しい .NET コンソール プロジェクトを作成し、前のサンプル コードを Program.cs
ファイルにコピーします。次に、以下のコマンドを使ってプロジェクトを実行します。
dotnet run csharp-delete-index.csproj
注意
DropOne()
メソッドは出力を返しません。 Atlas UIを使用してインデックスのステータスを表示できます。
Java ドライバーを使用してコレクション上の Atlas Search インデックスを削除するには、 dropSearchIndex()
メソッドを使用します。 Java ドライバーv 4.11.0以上が必要です。
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションは、指定されたコレクション上の指定された Atlas Search インデックスを削除します。
1 import com.mongodb.client.MongoClient; 2 import com.mongodb.client.MongoClients; 3 import com.mongodb.client.MongoCollection; 4 import com.mongodb.client.MongoDatabase; 5 import org.bson.Document; 6 7 public class DeleteIndex { 8 public static void main(String[] args) { 9 // connect to your Atlas cluster 10 String uri = "<connection-string>"; 11 12 try (MongoClient mongoClient = MongoClients.create(uri)) { 13 // set namespace 14 MongoDatabase database = mongoClient.getDatabase("<database-name>"); 15 MongoCollection<Document> collection = database.getCollection("<collection>"); 16 // delete the index 17 collection.dropSearchIndex("<index-name>"); 18 } 19 } 20 }
以下の値を置き換えて、ファイルを保存します。
<connection-string>
- Atlas接続文字列。 詳しくは、「ドライバーによる接続 」を参照してください。注意
接続文字列には、 writeConcern設定を含めないでください。
<database-name>
- コレクションを含むデータベースの名前。<collection-name>
- インデックスを検索するコレクションの名前。<index-name>
- 削除するインデックスの名前。
以下も参照してください。
Node Driverを通じて Atlas Search インデックスを削除するには、 dropSearchIndex
ヘルパー メソッドを使用します。
例
drop-index.js
という名前の次のサンプル アプリケーションを使用して、コレクションのインデックスを削除できます。 次の値を指定します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
検索インデックスを作成したデータベースとコレクション。
削除するインデックスの名前。
// connect to your Atlas deployment const uri = "<connection-string>"; const client = new MongoClient(uri); async function run() { try { const database = client.db("<databaseName>"); const collection = database.collection("<collectionName>"); // run the helper method await collection.dropSearchIndex("<index-name>"); } finally { await client.close(); } } run().catch(console.dir);
サンプル アプリケーションを実行するには、次のコマンドを使用します。
node drop-index.js
注意
dropSearchIndex
メソッドは出力を返しません。 Atlas UIを使用してインデックスのステータスを表示できます。
Python ドライバーを使用して Atlas Search インデックスを削除するには、コレクションでdrop_search_index()
メソッドを呼び出します。
例
次のコード例を ファイルにコピーします。
次のサンプル アプリケーションでは、Atlas Search インデックス名をdrop_search_index()
メソッドに渡してインデックスを削除します。
from pymongo.mongo_client import MongoClient def delete_index(): # Connect to your Atlas deployment uri = "<connectionString>" client = MongoClient(uri) # Access your database and collection database = client["<databaseName>"] collection = database["<collectionName>"] # Delete your search index collection.drop_search_index("<indexName>")
次の値を指定して、ファイルを保存します。
Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。
インデックスを削除するデータベースとコレクション。
削除するインデックスの名前。
インデックスのサイズを見積もる
mongot
プロセスはインデックス付きフィールドと _id
フィールドをディスクに保存するため、インデックスを構築する前にインデックスのサイズを調整することをお勧めします。 Atlas Searchインデックスの完全なサイズを見積もるには、コレクションのサブセットにインデックスを作成し、次の式を使用してデータの合計サイズに基づいてサンプルデータインデックスのサイズをスケーリングします。
estimated-index-size = ( subset-data-index-size / subset-data-size ) x total-collection-data-size
例、 データベース内のmovies
コレクションのインデックスのサイズを見積もる場合は、sample_mflix
mongosh
で次の手順を実行します。
$sample
データのランダムなサンプルを使用して、 を実行して という新しいコレクションを作成します。sample_data
use sample_mflix db.movies.aggregate([ { $sample: { size: 10 } }, { $out: "sample_data" } ]) [ { _id: ObjectId('573a13bbf29313caabd53f9c'), plot: "Three years ago, in real-life, Hama Ali, a charismatic actor from Iraq famous locally for his performance as Iraq's version of Superman, met Ayca on a film-set. He and Ayca, a fiery actress...", genres: [ 'Drama', 'Romance', 'War' ], runtime: 93, cast: [ 'Ayèa Damgaci', 'Hama Ali Kahn', 'Cengiz Bozkurt', 'Nesrin Cavadzade' ], num_mflix_comments: 1, poster: 'https://m.media-amazon.com/images/M/MV5BMjA1OTI1MjI4OV5BMl5BanBnXkFtZTgwODk1MTA2MDE@._V1_SY1000_SX677_AL_.jpg', title: 'Gitmek: My Marlon and Brando', fullplot: "Three years ago, in real-life, Hama Ali, a charismatic actor from Iraq famous locally for his performance as Iraq's version of Superman, met Ayca on a film-set. He and Ayca, a fiery actress from Turkey, had a passionate love affair before returning to their respective homes. From his Kurdish village, Hama Ali sends Ayca video love letters which he has filmed on his handycam. She watches them from her sofa in Istanbul, with her cat for company. The video love letters capture the hellish violence engulfing Iraq, the goats and uncles populating his rural area, and also his tender affection towards her. Feeling suffocated by her own city and angered by the indifference towards the war that surrounds her, Ayca decides to make the journey eastwards to Iraq to be reunited with her lover. GITMEK, a dramatic feature film, is based on the true story of Ayca's departure from Istanbul and her extraordinary journey to the Iraqi border. At a time when many people were fleeing from East to West in search of safety, Ayca makes the opposite journey, in search of love. She is helped by immigrant artists who live in the slums of Istanbul and the mothers of long distance truck drivers who she meets at various border towns. The journey takes her through breathtaking landscapes, strange encounters and terrifying times.", languages: [ 'English', 'Kurdish', 'Turkish' ], released: ISODate('2008-11-14T00:00:00.000Z'), directors: [ 'Huseyin Karabey' ], writers: [ 'Ayèa Damgaci', 'Huseyin Karabey' ], awards: { wins: 12, nominations: 4, text: '12 wins & 4 nominations.' }, lastupdated: '2015-07-04 00:20:59.083000000', year: 2008, imdb: { rating: 6.6, votes: 628, id: 920460 }, countries: [ 'Turkey' ], type: 'movie', tomatoes: { viewer: { rating: 3.7, numReviews: 181, meter: 79 }, lastUpdated: ISODate('2015-07-16T18:10:38.000Z') } }, { _id: ObjectId('573a139af29313caabcefb6a'), plot: '48 hours of intersecting lives and crimes in Los Angeles.', genres: [ 'Comedy', 'Crime', 'Drama' ], runtime: 104, rated: 'R', cast: [ 'Danny Aiello', 'Greg Cruttwell', 'Jeff Daniels', 'Teri Hatcher' ], num_mflix_comments: 1, poster: 'https://m.media-amazon.com/images/M/MV5BZDI0ZmFmYTgtMTQ5OS00MTVmLTgwNWYtNzIyY2Y5NjYxNzgyXkEyXkFqcGdeQXVyNzc5MjA3OA@@._V1_SY1000_SX677_AL_.jpg', title: '2 Days in the Valley', fullplot: 'John Herzfeld deftly welds together a multitude of subplots-- a loser hitman and a cool assassin involved in an insurance scam; a washed-up director, turned suicidal, if only he had someone to care for his beloved dog; a snooty art dealer, wracked by kidney stones, cared for by his devoted assistant; a grungy deranged vice cop, now partnered with a fresh-faced rookie; and two beautiful and jealous women entangled in their deadly scheme--into a spoof of the crime thriller genre.', languages: [ 'English', 'Vietnamese' ], released: ISODate('1996-09-27T00:00:00.000Z'), directors: [ 'John Herzfeld' ], writers: [ 'John Herzfeld' ], awards: { wins: 0, nominations: 1, text: '1 nomination.' }, lastupdated: '2015-09-11 00:42:22.520000000', year: 1996, imdb: { rating: 6.5, votes: 15019, id: 115438 }, countries: [ 'USA' ], type: 'movie', tomatoes: { viewer: { rating: 3, numReviews: 14630, meter: 55 }, dvd: ISODate('2001-08-07T00:00:00.000Z'), critic: { rating: 6, numReviews: 53, meter: 60 }, lastUpdated: ISODate('2015-08-19T18:25:36.000Z'), consensus: 'A labyrinthine thriller with a host of memorable characters, 2 Days in the Valley is an uneven but intriguing thriller/black comedy.', rotten: 21, production: 'HBO Video', fresh: 32 } }, { _id: ObjectId('573a13bdf29313caabd5943e'), fullplot: "When Emily Parris exposes a secret society of teenage girls who have slipped out of the world of social media and into another world they've discovered in the woods at night. When she accuses the girls of committing sexually deviant activities, Emily sends the small American town into a atmosphere of hysteria and the national media spotlight. The mystery deepens when each of the accused girls upholds a vow of silence.", imdb: { rating: 6.2, votes: 861, id: 1015471 }, year: 2014, plot: "When a teenage girl says she's the victim of a secret network called The Sisterhood of Night, a quiet suburban town becomes the backdrop for a modern-day Salem witch trial.", genres: [ 'Drama', 'Mystery', 'Thriller' ], rated: 'PG-13', metacritic: 60, title: 'The Sisterhood of Night', lastupdated: '2015-09-10 17:22:16.113000000', languages: [ 'English' ], writers: [ 'Marilyn Fu (screenplay)', 'Steven Millhauser (short story)' ], type: 'movie', tomatoes: { website: 'http://www.thesisterhoodofnight-movie.com/', viewer: { rating: 3.6, numReviews: 382, meter: 65 }, dvd: ISODate('2015-06-09T00:00:00.000Z'), critic: { rating: 6.6, numReviews: 19, meter: 79 }, boxOffice: '$5.3k', rotten: 4, production: 'Cine Mosaic', lastUpdated: ISODate('2015-09-13T17:24:37.000Z'), fresh: 15 }, poster: 'https://m.media-amazon.com/images/M/MV5BODg3MjE0MDM4N15BMl5BanBnXkFtZTgwOTY0MjE5NDE@._V1_SY1000_SX677_AL_.jpg', num_mflix_comments: 1, released: ISODate('2014-10-18T00:00:00.000Z'), awards: { wins: 2, nominations: 3, text: '2 wins & 3 nominations.' }, countries: [ 'USA' ], cast: [ 'Georgie Henley', 'Kara Hayward', 'Willa Cuthrell', 'Olivia DeJonge' ], directors: [ 'Caryn Waechter' ], runtime: 104 }, { _id: ObjectId('573a13c4f29313caabd6d7bf'), plot: 'A film producer struggles with suicidal despair.', genres: [ 'Drama' ], runtime: 110, metacritic: 76, cast: [ 'Louis-Do de Lencquesaing', 'Chiara Caselli', 'Alice de Lencquesaing', 'Alice Gautier' ], num_mflix_comments: 0, poster: 'https://m.media-amazon.com/images/M/MV5BMTUxODczODA2NV5BMl5BanBnXkFtZTcwNzExMjQ1Mw@@._V1_SY1000_SX677_AL_.jpg', title: 'Father of My Children', fullplot: "In the first half, Gregoire, a movie producer of great charm, owner of Moon Films, plays with his younger daughters, talks with his wife and his eldest daughter, and keeps his studio going while one project hemorrhages money and creditors circle. In the second half, Sylvia, his Italian wife, tries to hold the family together as she looks fully into Moon Films' troubles. She meets with a banker, a temperamental Swede, Russian TV magnates, a film lab exec, and Moon's lawyer. Clèmence, the oldest daughter, goes on her own search. Debt can crush; how does a family pick up the pieces?", languages: [ 'French' ], released: ISODate('2009-12-16T00:00:00.000Z'), directors: [ 'Mia Hansen-Lève' ], writers: [ 'Mia Hansen-Lève (screenplay)' ], awards: { wins: 2, nominations: 3, text: '2 wins & 3 nominations.' }, lastupdated: '2015-09-02 00:01:22.897000000', year: 2009, imdb: { rating: 6.7, votes: 1820, id: 1356928 }, countries: [ 'France', 'Germany', 'Belgium' ], type: 'movie', tomatoes: { website: 'http://www.filmsdulosange.fr/fr/fr_peredemesenfants.html', viewer: { rating: 3.3, numReviews: 1232, meter: 60 }, dvd: ISODate('2010-06-21T00:00:00.000Z'), critic: { rating: 7.4, numReviews: 55, meter: 91 }, lastUpdated: ISODate('2015-09-11T18:38:12.000Z'), consensus: 'A tragedy gracefully lifted by tender empathy and moments of joy, Father of My Children is a quiet triumph for writer-director Mia Hansen-Love.', rotten: 5, production: 'IFC Films', fresh: 50 } }, { _id: ObjectId('573a13a5f29313caabd15cc1'), plot: 'After a 13-year imprisonment in Hong Kong, a kickboxer challenges the current champion in order to restore his honor.', genres: [ 'Drama', 'Romance', 'Sport' ], runtime: 105, cast: [ 'Andy Lau', 'Takako Tokiwa', 'Inthira Charoenpura', 'Apichaya Thanatthanapong' ], title: 'Ah Fu', lastupdated: '2015-09-14 12:56:13.823000000', languages: [ 'Cantonese' ], released: ISODate('2000-11-21T00:00:00.000Z'), directors: [ 'Daniel Lee' ], writers: [ 'Chi-Sing Cheung', 'Daniel Lee' ], awards: { wins: 1, nominations: 3, text: '1 win & 3 nominations.' }, year: 2000, imdb: { rating: 6.6, votes: 350, id: 277558 }, countries: [ 'Hong Kong' ], type: 'movie', tomatoes: { viewer: { rating: 3.3, numReviews: 644, meter: 57 }, lastUpdated: ISODate('2015-04-25T18:41:33.000Z') }, num_mflix_comments: 0 }, { _id: ObjectId('573a13bef29313caabd5ce2b'), plot: 'Johann Sebastian Bach llega con su familia a Leipzig para ocupar el puesto de cantor en la Escuela de Santo Tomès...', genres: [ 'Musical' ], runtime: 102, metacritic: 70, cast: [ 'Christian Atanasiu', 'Fèodor Atkine', 'George-Christoph Biller', 'Christian Brembeck' ], title: 'The Silence Before Bach', lastupdated: '2015-05-25 00:50:52.210000000', languages: [ 'Spanish', 'German', 'Catalan' ], released: ISODate('2007-12-21T00:00:00.000Z'), directors: [ 'Pere Portabella' ], writers: [ 'Xavier Albertè', 'Pere Portabella', 'Carles Santos' ], awards: { wins: 3, nominations: 3, text: '3 wins & 3 nominations.' }, year: 2007, imdb: { rating: 6.8, votes: 329, id: 1079450 }, countries: [ 'Spain' ], type: 'movie', tomatoes: { website: 'http://www.pereportabella.com/eng/fla/die/home_eng.html', viewer: { rating: 3.5, numReviews: 391, meter: 64 }, critic: { rating: 6.6, numReviews: 16, meter: 81 }, lastUpdated: ISODate('2015-08-11T19:15:49.000Z'), rotten: 3, production: 'Film Forum', fresh: 13 }, num_mflix_comments: 0 }, { _id: ObjectId('573a13ccf29313caabd83260'), plot: 'A woman subject to mental, physical, and sexual abuse on a remote island seeks a way out.', genres: [ 'Crime', 'Drama', 'Horror' ], runtime: 115, cast: [ 'Yeong-hie Seo', 'Seong-won Ji', 'Min-ho Hwang', 'Min Je' ], num_mflix_comments: 0, poster: 'https://m.media-amazon.com/images/M/MV5BMjAyNDEwMDgzMl5BMl5BanBnXkFtZTcwNzMyMTYwNQ@@._V1_SY1000_SX677_AL_.jpg', title: 'Bedevilled', fullplot: "Hae-won is a beautiful single woman in her thirties who works at a bank in the Seoul city. She leads a busy life until she becomes a witness to an attempted murder case, and at the same time, things get complicated at work. When things get out of hand she is forced to take a vacation so she heads for 'Moodo', a small undeveloped island, where she had once visited to see her grandparents. And where she had befriended a girl named Bok-nam who stills writes to Hae-won asking her to visit despite the fact that Hae-won never bothered to reply. Upon arriving at the island, Hae-won is shocked to see everyone treating Bok-nam like a slave. As practically the only young woman on the island, she is a plaything for all the men and a free laborer for the women. Sick of all the inhumane treatment, Bok-nam had tried to escape the island several times in the past but had failed each time. She begs Hae-won to help her escape the place, but Hae-won remains indifferent not wanting to be involved in complicated situations. When Bok-nam realizes that her own daughter will follow her footsteps, she tries to escape the island with her daughter.", languages: [ 'Korean' ], released: ISODate('2010-09-02T00:00:00.000Z'), directors: [ 'Cheol-soo Jang' ], writers: [ 'Kwang-young Choi' ], awards: { wins: 10, nominations: 5, text: '10 wins & 5 nominations.' }, lastupdated: '2015-09-01 01:18:02.960000000', year: 2010, imdb: { rating: 7.3, votes: 7983, id: 1646959 }, countries: [ 'South Korea' ], type: 'movie' }, { _id: ObjectId('573a13c7f29313caabd746fe'), plot: 'A Californian family inherits a castle in Romania. This is especially exciting to the son, who is obsessed with monsters. And he is not disappointed.', genres: [ 'Comedy', 'Family' ], runtime: 83, rated: 'TV-G', cast: [ 'Victoria Justice', 'Chase Ellison', 'Anna Galvin', 'Matt Winston' ], num_mflix_comments: 0, poster: 'https://m.media-amazon.com/images/M/MV5BMjU1MmJlMTctY2FiMC00MmU1LWI5NmYtMDc5OWM0NjEzMmI2XkEyXkFqcGdeQXVyNDgyODgxNjE@._V1_SY1000_SX677_AL_.jpg', title: 'The Boy Who Cried Werewolf', fullplot: 'A Californian family inherits a castle in Romania. This is especially exciting to the son, who is obsessed with monsters. And he is not disappointed.', languages: [ 'English' ], released: ISODate('2010-10-22T00:00:00.000Z'), directors: [ 'Eric Bross' ], writers: [ 'Art Edler Brown', 'Douglas Sloan' ], awards: { wins: 1, nominations: 2, text: '1 win & 2 nominations.' }, lastupdated: '2015-08-20 00:01:59.673000000', year: 2010, imdb: { rating: 6.3, votes: 1582, id: 1451423 }, countries: [ 'USA', 'Canada' ], type: 'movie', tomatoes: { viewer: { rating: 3.7, numReviews: 762, meter: 66 }, lastUpdated: ISODate('2015-09-12T17:30:20.000Z') } }, { _id: ObjectId('573a13b4f29313caabd3f473'), genres: [ 'Documentary' ], runtime: 85, title: 'Zero Degrees of Separation', countries: [ 'Canada' ], lastupdated: '2015-08-09 00:30:38.977000000', languages: [ 'Arabic', 'English', 'Hebrew' ], released: ISODate('2005-06-22T00:00:00.000Z'), directors: [ 'Elle Flanders' ], writers: [ 'Elle Flanders' ], awards: { wins: 1, nominations: 0, text: '1 win.' }, year: 2005, imdb: { rating: 6.6, votes: 90, id: 454990 }, type: 'movie', tomatoes: { viewer: { rating: 3.5, numReviews: 5, meter: 100 }, fresh: 1, critic: { numReviews: 2 }, rotten: 1, lastUpdated: ISODate('2015-01-04T23:25:58.000Z') }, num_mflix_comments: 0 }, { _id: ObjectId('573a13bff29313caabd5f070'), plot: 'This hilarious genre-bending comedy follows Gary Brewer, along with girlfriend Holly Brewer (no relation), and best friend Trevor Morehouse as Gary quests to reign supreme at the 2006 Rock, Paper, Scissors World Championships.', genres: [ 'Comedy' ], runtime: 85, cast: [ 'Tim Doiron', 'April Mullen', 'Ryan Tilley', 'Peter Pasyk' ], num_mflix_comments: 0, poster: 'https://m.media-amazon.com/images/M/MV5BMTI5MzIwMjA2Ml5BMl5BanBnXkFtZTcwOTcyOTA4MQ@@._V1_SY1000_SX677_AL_.jpg', title: 'Rock, Paper, Scissors: The Way of the Tosser', fullplot: 'This hilarious genre-bending comedy follows Gary Brewer, along with girlfriend Holly Brewer (no relation), and best friend Trevor Morehouse as Gary quests to reign supreme at the 2006 Rock, Paper, Scissors World Championships.', languages: [ 'English' ], released: ISODate('2007-07-06T00:00:00.000Z'), directors: [ 'Tim Doiron', 'April Mullen' ], writers: [ 'Tim Doiron (creator)', 'April Mullen (creator)', 'Tim Doiron' ], awards: { wins: 2, nominations: 0, text: '2 wins.' }, lastupdated: '2015-08-12 00:01:33.813000000', year: 2007, imdb: { rating: 6.2, votes: 316, id: 1121964 }, countries: [ 'Canada' ], type: 'movie' } ] 完全なコレクションに使用するインデックス定義を使用して、サンプルデータとコレクションに検索インデックスを作成します 。
db.sample_data.createSearchIndex( "sample-index", { mappings: { dynamic: true } } ) sample-index サンプルデータのサイズをコレクションの合計サイズでスケーリングします。例、Atlas UIインデックスの概要ページ によると、
sample-index
インデックスのサイズが 44.88 の場合、次のコマンドを使用してインデックスの合計サイズを計算できます。let sampleSize = db.sample_data.totalSize() let totalSize = db.movies.totalSize() let totalIndexSize = ( 44.88 / sampleSize ) * totalSize; totalIndexSize 45864.28
インデックスのステータスの確認
Atlas UIでは、Atlas Search ページの Status 列に、クラスターのプライマリノード上のインデックスの現在のステータスが表示されます。次の表では、利用可能なインデックスのステータスについて説明しています。
ステータス | 説明 |
---|---|
支払い待ち | Atlas によるインデックスの構築は開始されていません。 |
構築 | Atlas はインデックスを構築中、または編集したインデックスを再構築中です。インデックスがこの状態のとき、次の状況が発生します。
|
Ready | インデックスをいつでも使用できます。 |
Stale | 次のいずれかの理由でインデックスが古くなっています。
既存のインデックスをクエリすることはできます。ただし、古いインデックスに対するクエリの結果には古いデータが含まれる場合があります。検索ノードをアップスケールしてディスク容量を増やしたり、既存のインデックスを削除してディスク容量を解放したりできます。または、View status details モーダルウィンドウのエラーを使用して問題のトラブルシューティングを行います。詳しくは、「Atlas Search の問題の修正」を参照してください。 |
失敗 | Atlas によるインデックスの構築は失敗しました。View status details モーダル ウィンドウのエラーを使用して、問題のトラブルシューティングを行います。詳しくは、「Atlas Search の問題の修正」を参照してください。 |
削除 | Atlas はクラスター ノードからインデックスを削除しています。 |
Does not Exist | インデックスのコレクションが存在しないため、インデックスは無効です。このインデックスに対応するコレクションがないため、このインデックスに対してクエリを実行することはできません。Atlas は最終的にインデックスを削除します。 |
Status Details ページでは次のいずれかの方法で詳細なステータス情報を表示できます。
Status 列の View status details リンクをクリックします。
Index Name 列の名前をクリックし、Index Overview の左側にあるメニューから Status Details を選択します。
Status Details ページには、次のセクションが含まれています。
クエリを処理するインデックス
このセクションでは、クエリを処理するために使用されているインデックスを表示します。
コレクションにこの名前のインデックスのバージョンが 1 つしかない場合は、そのセクションに Index Overview へのリンクがあり、使用されているインデックスのインデックス定義を確認できます。
コレクションに同じ名前のインデックスが他にもある場合、セクションには最新のインデックス定義が表示され、別のタブにコピーできる以前の有効なインデックスも表示されます。
インデックスを更新すると、ノードによって更新の適用速度が異なります。したがって、最新バージョンを使用するノードと、以前のバージョンを使用するノードがある可能性があります。Atlas は、変更がすべてのノードに適用されるまで、インデックスの両方のバージョンを表示します。
無効なインデックス定義でインデックスの更新を試みると、インデックス構築は失敗し、Atlas は以前の有効なインデックス定義のみを表示します。
ノード別のステータス詳細
このセクションには、クラスターの各ノードにおけるインデックスのステータスが表示されます。各ノードのインデックスに関する次の詳細を確認できます。
Shard | シャード名。 |
Node | ノードの情報。 |
Status | シャード内のノード上のインデックスのステータス。 |
Queryable | インデックスがクエリを処理できるかどうかを示すアイコン。 |
Message | インデックスのステータスの理由。 |
Node Type | ノードのタイプ。値は次のいずれかのタイプにできます。
|
Region | ノードのリージョン。 |
Size | ノード上のインデックスのサイズ。 |
Documents | インデックス作成されたドキュメントの数と割合。 |
Actions | ノードのインデックスに対して実行できるアクション。 をクリックし、以下のオプションのいずれかを選択できます。
|
検索ノードへの移行
このセクションでは、該当する場合、Atlas Search および Atlas ベクトル検索インデックスの検索ノードへの進行中の移行のステータスが表示されます。このセクションは、現在検索ノードに移行している場合にのみ表示されます。
検索ノードへのインデックスの移行の進捗状況(ノードごと)の詳細については、Index Status by Search Node セクションの情報バナーにある View Migration Progress リンクをクリックしてください。
Atlas UI には、クラスター上の各インデックスに対して次の列が表示されます。
コラム | 説明 |
---|---|
Database | コレクションを含むデータベースの名前。 |
Collection | インデックス作成されたコレクションの名前。 |
Index Name | インデックスの名前。 |
Index Fields | |
Type | インデックスのタイプ。値は、次のいずれかのタイプのインデックスです。
|
Status | 移行のステータス。 詳細については、「 検索ノードへの移行 」を参照してください。 |
Size | インデックスのサイズ。 |
Documents | クラスター上の検索ノードでの移行中および移行後のコレクション内のドキュメントの総数に対するインデックス付きドキュメントの数と割合。 |
ステータス列には、検索ノード上のインデックスの次のいずれかのステータスが表示されます。
ステータス | 説明 |
---|---|
構築 | インデックスは現在、検索ノード上に構築されています。新しいインデックスの構築中も、クエリでは既存のインデックスを引き続き使用できます。 |
On Deck | インデックスは検索ノード上に正常に構築されましたが、移行はまだ完了していません。Atlas が検索ノード上のすべてのインデックスを正常に構築した場合にのみ移行が完了することに注意してください。 |
Ready | 検索ノードのインデックスは、クエリで使用する準備が整いました。これは、Atlas が検索ノードへの移行を正常に完了した場合にのみ表示されます。 |
失敗 | インデックスの構築に失敗し、別の検索ノードへの移行が停止しました。クエリでは既存のインデックスを引き続き使用できます。Atlas はインデックスの再構築を試みますが、7 日後にタイムアウトします。 正常にインデックスするには、 ノードMessage 列またはStatus Details ページ でインデックスのエラー メッセージを確認し、検索ノードでインデックス構築が失敗する原因となっている問題に対処してください。 |
検索ノードで新しいインデックスを作成する間も、クエリは既存のインデックスを引き続き使用できます。検索ノードへの移行は、Atlas が検索ノード上のすべてのインデックスを正常にビルドした場合にのみ完了します。その後、クエリは自動的に にルーティングされ、検索ノードのインデックスを使用できます。
詳細
Atlas Search クエリのニーズを満たすために Atlas Searchインデックスを定義する方法については、「クエリの定義」を参照してください。
Atlas Searchインデックスの作成方法については、「 Atlas Searchインデックスの作成 」を参照してください。
このチュートリアルで説明する Atlas Searchインデックス構成の詳細については、次の参照ページを参照してください。
サンプルデータセット用の Atlas Search インデックスの作成、およびインデックス付きデータに対する Atlas Search クエリの実行中に関する実践的な情報については、 Atlas Search クイック スタートを試してください。
学び続ける
ビデオで学ぶ
このビデオ チュートリアルでは、複雑度がさまざまに異なる Atlas Search インデックスの作成方法を紹介します。
所要時間: 15 分