MongoDB\Collection::createSearchIndex()
バージョン 1.17 の新機能。
定義
MongoDB\Collection::createSearchIndex()
Create an Atlas Search or Vector Search index for the collection.
function createSearchIndex( array|object $definition, array $options = [] ): string このコマンドは、 MongoDB Atlasでホストされている配置でのみ実行でき、少なくとも M 10の Atlas クラスター階層が必要です。 Atlas のローカル配置は、開発にも使用できます。
パラメーター
$definition
: array|object- 作成するインデックスを説明するドキュメント。 定義構文の詳細については、「検索インデックスの定義構文 」を参照してください。
$options
: 配列必要なオプションを指定する配列。
名前タイプ説明comment
混合
name
string
Name of the search index to create.You cannot create multiple indexes with the same name on a single collection. If you do not specify a name, the default index name isdefault
.タイプ
string
Type of index to create. Accepted values are
'search'
and'vectorSearch'
. If you omit this option, the default value is'search'
and the method creates an Atlas Search index.
Return Values
The name of the created Atlas Search or Vector Search index as a string.
エラーと例外
MongoDB\Exception\UnsupportedException
オプションが使用され、選択したサーバーでサポートされていない場合(例: collation
、 readConcern
、 writeConcern
)。
パラメータまたはオプションの解析に関連するエラーは、 MongoDB\Exception\InvalidArgumentException
。
MongoDB\Driver\Exception\RuntimeException 拡張レベルのその他のエラー(例:)。
動作
Atlas Search インデックスとベクトル検索インデックスは非同期で管理されます。インデックスを作成または更新した後、MongoDB\Collection::listSearchIndexes()
を定期的に実行し、queryable
出力フィールド を確認して、使用可能かどうかを判断します。
例
動的マッピングによるインデックスの作成
次の例では、動的マッピングを使用して Atlas Search インデックスを作成し、サポートされているデータ型を含むすべてのドキュメント フィールドにインデックスを作成します。
$collection = (new MongoDB\Client)->selectCollection('test', 'articles'); $indexName = $collection->createSearchIndex( ['mappings' => ['dynamic' => true]], ['name' => 'test-search-index'] ); var_dump($indexName);
出力は次のようになります。
string(17) "test-search-index"
その他の参照
Atlas Search インデックス guide
MongoDB マニュアルのcreateSearchIndexesコマンドに関する参考資料
MongoDB マニュアルのAtlas Searchのドキュメント