Docs Menu
Docs Home
/
MongoDB Atlas
/ /

View an Atlas Search Index

On this page

  • Required Access
  • View an Atlas Search Index

Important

If you use the $out aggregation stage to modify a collection with an Atlas Search index, you must delete and re-create the search index. If possible, consider using $merge instead of $out.

You can view an Atlas Search index definition in the Index Overview page. For each index, the Index Overview page shows the following:

  • Namespace for the index.

  • Index and search analyzers specified in the index definition.

  • Dynamic or static mapping.

  • Field mappings in the index definition, if any, including field name, data type, and whether dynamic mapping is enabled for the individual field.

This page describes how to view your index definition in the Index Overview page. You can also Edit an Atlas Search Index with the visual or JSON editor in the Index Overview page.

The following table shows the modes of access each role supports.

Role
Action
Atlas UI
Atlas API
Atlas Search API
Atlas CLI
To view Atlas Search analyzers and indexes.
✓
✓
To create and manage Atlas Search analyzers and indexes, and assign the role to your API Key.
✓
✓
✓
✓
✓
✓
To create access list entries for your API Key and send the request from a client that appears in the access list for your API Key.
✓
✓
To create, view, edit, and delete Atlas Search indexes using the Atlas UI or API.
✓
✓
✓

You can retrieve your Atlas Search indexes in the Atlas UI, or programmatically by using mongosh, the Atlas CLI, the API, or a supported MongoDB Driver in your preferred language.

Note

You can't use the mongosh command or driver helper methods to retrieve Atlas Search indexes on M0, M2, or M5 Atlas clusters. To create and manage Atlas Search indexes using mongosh or the driver, upgrade to a dedicated cluster tier.

You must have at least the readAnyDatabase role or read access to the database that contains the indexes. To learn more, see Built-in Roles or Specific Privileges.


➤ Use the Select your language drop-down menu to set the language of the example in this section.


To retrieve an Atlas Search index through the API:

1

Send a GET request with either the unique ID or name of the Atlas Search index that you wish to retrieve to the search/indexes/ endpoint.

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

To learn more about the syntax and parameters for either endpoint, see Get One By Name and Get One By ID.

2

To retrieve all Atlas Search indexes for a collection:

1

Send a GET request to the search/indexes/ endpoint with the name of the collection whose indexes you want to retrieve.

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}"
2

To retrieve all Atlas Search indexes for a cluster:

1

Send a GET request to the search/indexes/ endpoint with the name of the cluster whose indexes you want to retrieve.

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"
2

To list all search indexes for a cluster using the Atlas CLI, run the following command:

atlas clusters search indexes list [options]

To return the details for the search index you specify using the Atlas CLI, run the following command:

atlas clusters search indexes describe <indexId> [options]

To learn more about the syntax and parameters for the previous commands, see the Atlas CLI documentation for atlas clusters search indexes list and atlas clusters search indexes describe.

Tip

See: Related Links

To describe the specified search index for the specified deployment using the Atlas CLI, run the following command:

atlas deployments search indexes describe [indexId] [options]

To list all search indexes for the specified deployment using the Atlas CLI, run the following command:

atlas deployments search indexes list [options]

To learn more about the syntax and parameters for the previous commands, see the Atlas CLI documentation for atlas deployments search indexes describe and atlas deployments search indexes list.

1
  1. If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. If the Clusters page is not already displayed, click Database in the sidebar.

2

You can go the Atlas Search page from the sidebar, the Data Explorer, or your cluster details page.

  1. In the sidebar, click Atlas Search under the Services heading.

  2. From the Select data source dropdown, select your cluster and click Go to Atlas Search.

  1. Click the Browse Collections button for your cluster.

  2. Expand the database and select the collection.

  3. Click the Search Indexes tab for the collection.

  1. Click the cluster's name.

  2. Click the Atlas Search tab.

3

To retrieve your Atlas Search indexes through mongosh, use the db.collection.getSearchIndexes() method.

The command has the following syntax. If you omit the index name, Atlas Search returns all indexes on the collection.

db.<collection>.getSearchIndexes("<index-name>")

The following command retrieves a search index named default from the movies collection. Your results should resemble the example output:

db.movies.getSearchIndexes("default")
[
{
id: '648b4ad4d697b73bf9d2e5e0',
name: 'default',
status: 'READY',
queryable: true,
latestDefinition: { mappings: { dynamic: true } }
}
]

To use the C Driver to retrieve your Atlas Search indexes, use the mongoc_collection_aggregate() method to create an aggregation pipeline that includes the $listSearchIndexes stage.

1
2

The following sample application specifies the $listSearchIndexes stage in an aggregation pipeline. Then, the application passes the pipeline and the target collection to the mongoc_collection_aggregate() method. This method returns a cursor from which the code accesses and prints each Atlas Search index:

#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;
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;
}
3
  • Your Atlas connection string. To learn more, see Connect via Drivers.

  • The database and collection for which you want to retrieve the indexes.

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

To use the C++ Driver to retrieve your Atlas Search indexes, call the list() method on a search index view.

1
2

The following sample application uses the search_indexes() method on the target collection to instantiate a search index view. Then, the application calls the list() method on the view. This method returns a cursor from which the code accesses and prints each Atlas Search index.

#include <bsoncxx/json.hpp>
#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 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;
}
3
  • Your Atlas connection string. To learn more, see Connect via Drivers.

  • The database and collection for which you want to retrieve the indexes.

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

To use the .NET/C# Driver to retrieve your Atlas Search indexes, use the List() or ListAsync() method.

The following sample application returns the indexes on a collection. Specify the following values:

  • Your Atlas connection string. To learn more, see Connect via Drivers.

  • The database and collection that contains the search indexes that you want to retrieve.

Note

The List() method returns a cursor instead of the indexes themselves. To access the indexes, use a cursor paradigm such as the MoveNext() method.

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");
// list your Atlas Search indexes
var result = collection.SearchIndexes.List().ToList();
foreach (var index in result)
{
Console.WriteLine(index);
}

To run the sample application, create a new .NET console project named csharp-list-indexes and copy the previous code example into the Program.cs file. Then, use the following command to run the project:

dotnet run csharp-list-indexes.csproj
<indexes for this collection>

To retrieve Atlas Search indexes on a collection using the Java Driver, use the listSearchIndexes() method. You must have Java Driver v4.11.0 or higher.

1
2

The following sample application retrieves all Atlas Search indexes on a given collection.

1import com.mongodb.client.MongoClient;
2import com.mongodb.client.MongoClients;
3import com.mongodb.client.MongoCollection;
4import com.mongodb.client.MongoCursor;
5import com.mongodb.client.MongoDatabase;
6import org.bson.Document;
7public 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}
3
  • <connection-string> - Your Atlas connection string. To learn more, see Connect via Drivers.

  • <database-name> - The name of the database that contains the collection.

  • <collection-name> - The name of the collection for which you want to retrieve the index.

4
javac ViewIndex.java
java ViewIndex

To retrieve your Atlas Search indexes through the Node Driver, use the listSearchIndexes helper method.

You can use the following sample application named list-indexes.js to return the indexes on your collection. Specify the following values:

  • Your Atlas connection string. To learn more, see Connect via Drivers.

  • The database and collection that contains the search indexes that you want to retrieve.

  • The index name if you want to retrieve a specific index. To return all indexes on the collection, omit this value.

Note

The listSearchIndexes command returns a cursor. As a result, it doesn't immediately return the indexes matched by the command. To access the results, use a cursor paradigm such as the toArray() method. To learn more, see Access Data From a Cursor.

list-indexes.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>");
// run the helper method
const result = await collection.listSearchIndexes("<index-name>").toArray();
console.log(result);
} finally {
await client.close();
}
}
run().catch(console.dir);

To run the sample application, use the following command. Your results should resemble the example output:

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' } } }
}
}
]

To use the Python Driver to retrieve your Atlas Search indexes, call the list_search_indexes() method on your collection.

1
2

The following sample application calls the list_search_indexes() method on a collection. This method returns a cursor from which the code accesses and prints each Atlas Search index:

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)
3
  • Your Atlas connection string. To learn more, see Connect via Drivers.

  • The database and collection for which you want to retrieve the indexes.

4
python view-index.py

Back

Resume or Delete a Draft

Next

Edit