Docs Menu
Docs Home
/
MongoDB Atlas
/ /

Atlas Search インデックスの削除

項目一覧

  • 必要なアクセス権
  • Atlas Search インデックスの削除

次の表は、指定された Atlas Search アクションに対して各ユーザー ロールがサポートするアクセス モードを示しています。

ロール
Atlas Search アクション
Atlas UI
Atlas CLI
Atlas API [1]

Project Data Access Read Only またはそれ以上

Atlas Search アナライザーとインデックスを表示します。

Project Data Access Admin またはそれ以上

Atlas Search アナライザとインデックスを作成および管理します。

Atlas Search インデックスを作成、表示、更新、削除します。

[1] 各ロールには、Atlas Administration APIの Atlas Search APIエンドポイントのサブセットまたは完全なセットを呼び出す権限が付与されます。各ロールがアクセスを許可するAPIエンドポイントの説明については、「 Atlas Search アクション 」列を参照してください。

Atlas Search インデックスは、Atlas UI で、またはmongosh 、Atlas CLI、 API 、または希望言語でサポートされているMongoDB ドライバーを使用してプログラム的に削除できます。

注意

mongoshコマンドまたはドライバーヘルパーメソッドを使用して、すべての Atlas クラスター階層上の Atlas Search インデックスを削除できます。サポートされているドライバー バージョンのリストについては、「 MongoDBドライバー 」を参照してください。

インデックスを含むデータベースに対して、少なくとも readWriteAnyDatabase ロールまたは readWrite アクセス権が必要です。詳しくは、「組み込みロール」または「特定の権限」を参照してください。


➤ [言語の選択]ドロップダウン メニューを使用して、このセクション内の例の言語を設定します。


APIを使用して Atlas Search インデックスを削除するには、次の手順に従います。

1

削除する 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 つの削除 」を参照してください。

2

Atlas CLI を使用してクラスターから検索インデックスを削除するには、次のコマンドを実行します。

atlas clusters search indexes delete <indexId> [options]

コマンド構文とパラメーターについて詳しくは、「Atlasクラスター検索インデックスの削除」の Atlas CLIドキュメントを参照してください。

Tip

参照: 関連リンク

Atlas CLI を使用して指定したデプロイの指定した検索インデックスを削除するには、次のコマンドを実行します。

atlas deployments search indexes delete <indexId> [options]

コマンド構文とパラメーターの詳細については、Atlas CLI ドキュメントの「atlas deployments search indexes delete」を参照してください。

1
  1. まだ表示されていない場合は、希望するプロジェクトを含む組織を選択しますナビゲーション バーのOrganizationsメニュー

  2. まだ表示されていない場合は、ナビゲーション バーのProjectsメニューから目的のプロジェクトを選択します。

  3. まだ表示されていない場合は、サイドバーの [Clusters] をクリックします。

    [ Clusters (クラスター) ] ページが表示されます。

2

GoAtlas Searchページには、サイドバー、Data Explorer 、またはクラスターの詳細ページから できます。

  1. サイドバーで、 Services見出しの下のAtlas Searchをクリックします。

    注意

    クラスターがない場合は、Create clusterをクリックしてクラスターを作成してください。詳細については、「 クラスターの作成 」を参照してください。

  2. [ Select data sourceドロップダウンからクラスターを選択し、[ Go to Atlas Search ] をクリックします。

    Atlas Searchページが表示されます。

  1. クラスターの [Browse Collections] ボタンをクリックします。

  2. データベースを展開し、コレクションを選択します。

  3. コレクションのSearch Indexesタブをクリックします。

    Atlas Searchページが表示されます。

  1. クラスタの名前をクリックします。

  2. [Atlas Search] タブをクリックします。

    Atlas Searchページが表示されます。

3

[ ellipsis ] ボタンはパネルの右側にあります。 目的のインデックスの横にある ボタンをクリックし、[ Delete Index ] を選択します。

4

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()メソッドに渡します。

1
2

次のサンプル アプリケーションでは、 dropSearchIndexコマンドと既存のインデックス名を指定します。 次に、アプリケーションはコマンドとインデックス情報をBSONに変換し、この情報をmongoc_collection_command_simple()メソッドに渡して検索インデックスを削除します。

#include <mongoc/mongoc.h>
#include <stdlib.h>
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;
}
3
  • Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。

  • インデックスを削除するデータベースとコレクション。

  • 削除するインデックスの名前。

4
gcc -o delete-index delete-index.c $(pkg-config --libs --cflags libmongoc-1.0)
./delete-index

C++ ドライバーを使用して Atlas Search インデックスを削除するには、検索インデックス ビューでdrop_one()メソッドを呼び出します。

1
2

次のサンプル アプリケーションでは、ターゲット コレクションのsearch_indexes()メソッドを使用して検索インデックス ビューをインスタンス化します。 次に、アプリケーションはビューでdrop_one()メソッドを呼び出し、インデックスを削除するためのパラメーターとして Atlas Search インデックス名を渡します。

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/search_index_view.hpp>
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;
}
3
  • Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。

  • インデックスを取得するデータベースとコレクション。

  • 削除するインデックスの名前。

4
g++ -o delete-index delete-index.cpp $(pkg-config --cflags --libs libmongocxx)
./delete-index

.NET/C# ドライバー を使用して Atlas Search インデックスを削除するには、 メソッドまたはDropOne() DropOneAsync()メソッドを使用します。

次のサンプル アプリケーションは、コレクションからインデックスを削除します。 次の値を指定します。

  • Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。

  • 削除する検索インデックスを含むデータベースとコレクション。

  • 削除する検索インデックスの名前。

Program.cs
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以上が必要です。

1
2

次のサンプル アプリケーションは、指定されたコレクション上の指定された Atlas Search インデックスを削除します。

1import com.mongodb.client.MongoClient;
2import com.mongodb.client.MongoClients;
3import com.mongodb.client.MongoCollection;
4import com.mongodb.client.MongoDatabase;
5import org.bson.Document;
6
7public 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}
3
  • <connection-string> - Atlas接続文字列。 詳しくは、「ドライバーによる接続 」を参照してください。

    注意

    接続文字列には、 writeConcern設定を含めないでください。

  • <database-name> - コレクションを含むデータベースの名前。

  • <collection-name> - インデックスを検索するコレクションの名前。

  • <index-name> - 削除するインデックスの名前。

4
javac DeleteIndex.java
java DeleteIndex

Tip

以下も参照してください。

Node Driverを通じて Atlas Search インデックスを削除するには、 dropSearchIndexヘルパー メソッドを使用します。

drop-index.jsという名前の次のサンプル アプリケーションを使用して、コレクションのインデックスを削除できます。 次の値を指定します。

  • Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。

  • 検索インデックスを作成したデータベースとコレクション。

  • 削除するインデックスの名前。

drop-index.js
// 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()メソッドを呼び出します。

1
2

次のサンプル アプリケーションでは、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>")
3
  • Atlas 接続文字列。詳しくは、「ドライバーによる接続」を参照してください。

  • インデックスを削除するデータベースとコレクション。

  • 削除するインデックスの名前。

4
python delete_index.py

戻る

編集