インデックスパーティションを構成する
項目一覧
インデックス作成において、Atlas Search は、ドキュメントが他のドキュメント内にネストされていない場合、各ドキュメントを 1 つのオブジェクトとして数えます。埋め込みドキュメントの場合、Atlas Search はネストのレベル数に応じて、各埋め込みドキュメントを追加のインデックスオブジェクトとしてカウントします。Atlas Search は、インデックスの変更のレプリケーションが 2,100,000,000 インデックスオブジェクトを超える場合、そのレプリケーションを停止します。
Atlas Search を別個の検索ノードに配置した場合、インデックスオブジェクトをサブインデックスにパーティショニングことで、Atlas Searchインデックスオブジェクトの数を増やすことができます。デフォルトでは 、Atlas Search は シャードごとに 1 つのパーティションをサポートしています。各パーティションは最大 2 億のインデックスオブジェクトをサポートします。 numPartitions
オプションを使用すると、最大 64 個(64
)のサブインデックスを作成できます。
インデックスのパーティションを設定すると、Atlas Search はインデックスオブジェクトをサブインデックス間で最適に自動分散します。サブインデックスを持つコレクションに対してクエリを実行する際、Atlas Search はクエリをすべてのサブインデックスに分散し、検索結果とメタデータを収集してソート、マージし、結果を返します。
次の場合、インデックスをパーティショニングすることをお勧めします。
インデックス オブジェクトが合計上限数の 50% に達しています。
コレクション内のドキュメントの数が 20 億に達します。
Atlas Search がレプリケーションを停止したため、インデックスは
STALE
の状態です。
サブインデックスを設定したり、サブインデックスの数を変更したりすると、Atlas Search はインデックスの再構築をトリガーします。
クラスターに複数のサブインデックスがある場合、すべての検索ノードを削除して、mongod
と mongot
の両方のプロセスが同じノードで実行される配置モデルに移行することはできません。
構文
1 { 2 "numPartitions": <integer> 3 }
サポートされている値
Atlas Search numPartitions
オプションは次の値を取ります。
1
- サブインデックスを追加せずに単一のインデックスを作成する。これはデフォルト値です。2
- 最大 2 つのサブインデックスを作成する。4
- 最大 4 つのサブインデックスを作成する。8
- 最大 8 つのサブインデックスを作成する。16
- 最大 16 個のサブインデックスを作成する。32
- 最大 32 個のサブインデックスを作成する。64
- 最大 64 個のサブインデックスを作成する。
例
次のインデックスの例では、sample_mflix.movies
コレクションを使用して、コレクション内のデータに最大 4
個のサブインデックスを設定する方法を示します。インデックスを作成するには、Atlas UI の Visual Editor または JSON エディター、および その他のサポートされているクライアントを使用できます。
➤ [言語の選択] ドロップダウン メニューを使用して、このセクションの例のクライアントを設定します。
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": "movies", "database": "sample_mflix", "name": "partitioned_index", "type": "search", "definition": { "analyzer": "lucene.standard", "mappings": { "dynamic": true, }, "numPartitions": 4, "searchAnalyzer": "lucene.standard" } }'
indexDef.json
という名前のファイルを以下のように作成します。{ "collectionName": "movies", "database": "sample_mflix", "definition": { "mappings": { "dynamic": true }, }, "name": "partitioned_index", "numPartitions": 4 } 以下のコマンドを実行してインデックスを作成します。
atlas deployments search indexes create --file indexDef.json
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 クエリのデフォルトの検索インデックスになります。複数のインデックスを作成する場合は、インデックス間で一貫した記述的な命名規則を維持することをお勧めします。
db.movies.createSearchIndex( "search-index", { mappings: { dynamic: true }, "numPartitions": 4 } )
using MongoDB.Bson; using MongoDB.Driver; // connect to your Atlas deployment var uri = "<connection-string>"; var client = new MongoClient(uri); var db = client.GetDatabase("sample_mflix"); var collection = db.GetCollection<BsonDocument>("movies"); // define your Atlas Search index var index = new BsonDocument { { "mappings", new BsonDocument { { "dynamic", true } } }, { "numPartitions", 4 } }; var result = collection.SearchIndexes.CreateOne(index, "partitioned_index"); Console.WriteLine(result);
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("sample_mflix"); MongoCollection<Document> collection = database.getCollection("movies"); Document index = new Document() .append("mappings", new Document() .append("dynamic", true) ) .append("numPartitions", 4); collection.createSearchIndex("partitioned_index", index); } } }
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("sample_mflix"); const collection = database.collection("movies"); // define your Atlas Search index const index = { name: "partitioned_index", definition: { /* search index definition fields */ "mappings": { "dynamic": true }, "numPartitions": 4 } } // run the helper method const result = await collection.createSearchIndex(index); console.log(result); } finally { await client.close(); } } run().catch(console.dir);
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["sample_mflix"] collection = database["movies"] # Create your index model, then create the search index search_index_model = SearchIndexModel( definition={ "mappings": { "dynamic": True }, "numPartitions": 4 }, name="partitioned_index", ) result = collection.create_search_index(model=search_index_model) print(result)