インデックス パーティションの構成
項目一覧
重要
numPartitions
オプションはプレビュー機能として利用できます。
インデックス作成の場合、Atlas Search は各ドキュメントが別のドキュメントにネストされていない場合、単一のインデックスオブジェクトとしてカウントします。埋め込みドキュメントの場合、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
プロセスの両方が 同じノードで実行される配置モデルに移行することはできません。
構文
{ "name": "<index-name>", "analyzer": "<analyzer-for-index>", "searchAnalyzer": "<analyzer-for-query>", "mappings": { "dynamic": <boolean>, "fields": { <field-definition> } }, "numPartitions": <integer>, ... }
サポートされている値
Atlas Search numPartitions
オプションには次の値があります。
1
- 追加のサブインデックスなしで、単一のインデックスを作成します。これはデフォルト値です。2
- では、最大 2 つのサブインデックスを作成します。4
- では、最大 4 つのサブインデックスを作成します。8
- では、最大 8 つのサブインデックスを作成します。16
- では、最大 60 個のサブインデックスが作成されます。32
- では、最大 32 個のサブインデックスが作成されます。64
- では、最大 64 個のサブインデックスが作成されます。
例
次のインデックス例では、sample_mflix.movies
4
コレクションを使用して、コレクション内のデータに対して最大 のサブインデックスを構成する方法を示します。 Atlas UIのビジュアル エディターまたは 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 のUIで、以下を選択します。
Search Type
Atlas Search
Index Name and Data Source
インデックス名:
partitioned_index
データ ソース:
sample_mflix.movies
Configuration Method
ビジュアル エディター
[ Nextをクリックし、 Refine Your Indexをクリックします。
Index Partitions を切り替えて有効にします。
[ ドロップダウンから
4
を選択し、[] をクリックします。Number of partitionsSave Changesインデックスを作成するには、 Create Indexをクリックします。
JSON エディター
Atlas のUIで、以下を選択します。
Search Type
Atlas Search
Index Name and Data Source
インデックス名:
partitioned_index
データ ソース:
sample_mflix.movies
Configuration Method
JSON エディター
デフォルトのインデックス定義を以下のように置き換えます。
{ "mappings": { "dynamic": true }, "numPartitions": 4 } Next、Create Index の順にクリックしてインデックスを作成します。
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)