Docs Menu
Docs Home
/ /

MongoDB\Collection::createSearchIndexes()

버전 1.17에 추가 되었습니다.

MongoDB\Collection::createSearchIndexes()

Create one or more MongoDB Search or Vector Search indexes for the collection.

function createSearchIndexes(
array $indexes,
array $options = []
): string

이 명령은 MongoDB Atlas 에 호스팅된 배포에서만 실행할 수 있으며, 10 이상의 Atlas 클러스터 계층이 필요합니다. 로컬 Atlas 배포서버 를 개발에도 사용할 수 있습니다.

$indexes : 배열

생성할 인덱스를 설명하는 문서의 배열입니다.

필수 definition 문서 필드는 생성할 인덱스를 설명합니다. 정의 구문에 대한 자세한 내용은 Atlas Search 인덱스 정의 구문을 참조하세요.

선택 사항인 name 문자열 필드 생성할 검색 인덱스 의 이름을 지정합니다. 단일 컬렉션 에 동일한 이름으로 여러 인덱스를 만들 수 없습니다. 이름을 지정하지 않으면 기본값 인덱스 이름은 default입니다.

An optional type string field specifies the type of search index to create. Accepted values are 'search' and 'vectorSearch'. If you do not specify a type, the method creates a MongoDB Search index.

$options : 배열

원하는 옵션을 지정하는 배열입니다.

이름
유형
설명

comment

혼합

The names of the created MongoDB Search and Vector Search indexes as an array of strings.

옵션이 사용되지만 선택한 서버에서 지원되지 않는 경우 MongoDB\Exception\UnsupportedException입니다(예: collation, readConcern, writeConcern).

MongoDB\Exception\InvalidArgumentException 매개변수 또는 옵션의 구문 분석과 관련된 오류의 경우입니다.

확장 수준의 기타 오류에 대한MongoDB\ 드라이버\Exception\RuntimeException(예: 연결 오류).

MongoDB Search 및 Vector Search 인덱스는 비동기적으로 managed 됩니다. 인덱스 생성하거나 업데이트한 후 주기적으로 를 MongoDB\Collection::listSearchIndexes() 실행하고 queryable 출력 필드 확인하여 사용할 준비가 되었는지 확인할 수 있습니다.

다음 예시 동적 매핑을 사용하여 지원되는 데이터 유형이포함된 모든 문서 필드를 인덱스 MongoDB Search 인덱스 만듭니다.

<?php
$collection = (new MongoDB\Client)->selectCollection('test', 'articles');
$indexNames = $collection->createSearchIndexes(
[
[
'name' => 'test-search-index',
'definition' => ['mappings' => ['dynamic' => true]],
],
]
);
var_dump($indexNames);

이 경우 출력은 다음과 유사합니다:

array(1) {
[0]=>
string(17) "test-search-index"
}

돌아가기

createSearchIndex()

이 페이지의 내용