파이프라인 단계
MongoDB Search queries take the form of an aggregation pipeline stage. MongoDB Search provides $search and $searchMeta stages, both of which must be the first stage in any query pipeline, including the $lookup and $unionWith sub-pipelines. These stages can be used in conjunction with other aggregation pipeline stages in your query pipeline.
선택한 파이프라인 단계에 따라 쿼리는 전체 텍스트 검색의 검색 결과 또는 검색 결과에 대한 메타데이터를 반환합니다.
집계 파이프라인 단계 | 목적 |
|---|---|
Full Text Search의 검색 결과를 반환합니다. | |
검색 결과에 대한 메타데이터를 반환합니다. |
연산자와 콜렉터
MongoDB Search는 및 $searchMeta 집계 $search 파이프라인 단계 내에서 사용할 수 있는 쿼리 연산자 및 수집기도 제공합니다. MongoDB Search 연산자를 사용하면 클러스터 의 컬렉션 에서 관련 데이터를 찾고 조회 수 있습니다. 수집기는 검색 메타데이터 결과를 나타내는 문서 반환합니다.
MongoDB Search 연산자를 사용하여 용어, 구문, 지리적 도형 및 점, 숫자 값, 유사 문서, 동의어 등 쿼리 수 있습니다.
You can also search using regex and wildcard expressions. The MongoDB Search compound operator allows you to combine multiple operators inside your $search stage to perform a complex search and filter of data based on what must, must not, or should be present in the documents returned by MongoDB Search. You can use the compound operator to also match or filter documents in the $search stage itself. Running $match after $search is less performant than running $search with the compound operator.
연산자와 수집기에 대한 자세한 내용은 연산자 및 수집기를 참조하세요.
쿼리 처리
mongod동일한 노드의mongotWhen you run a query, MongoDB Search uses the configured read preference to identify the node on which to run the query. The query first goes to the MongoDB process, which is
mongodfor a replica set cluster ormongosfor a sharded cluster.For a replica set cluster, the MongoDB process routes the query to the
mongoton the same node. For sharded clusters, your cluster data is partitioned acrossmongodinstances and eachmongotknows about the data on themongodon the same node only. Therefore, you can't run MongoDB Search queries that target a particular shard.mongosdirects the queries to all shards, making these scatter gather queries. If you use zones to distribute a sharded collection over a subset of the shards in the cluster, MongoDB Search routes the query to the zone that contains the shards for the collection that you are querying and runs your$searchqueries on just the shards where the collection is located.MongoDB Search는 검색 및 점수 산정을 수행하고 일치하는 결과에 대한 문서 ID 및 기타 검색 메타데이터
mongod에 반환합니다. 그런 다음mongod는 일치하는 결과에 대해 암시적으로 전체 문서 조회를 수행하고 결과를 클라이언트 에 반환합니다.쿼리에서
$search동시 옵션을 사용하는 경우 MongoDB Search는 쿼리 내 병렬 처리를 활성화합니다. 자세한 내용은 세그먼트 간 쿼리 실행 병렬 처리를 참조하세요.mongod및 다른 노드의mongotWhen you run a query, the query first goes to the
mongodbased on the configured read preference. By default, themongodprocess routes the search query through a load balancer on the same node, which distributes the requests across all of themongotprocesses. Alternatively, if you set thesearchNodePreferenceparameter for your$searchstage, MongoDB Search runs your query against the same search node each time.MongoDB Search
mongot프로세스 검색 및 점수 산정을 수행하고 일치하는 결과에 대한 문서 ID 및 메타데이터mongod에 반환합니다. 그런 다음mongod는 일치하는 결과에 대해 전체 문서 조회를 수행하고 결과를 클라이언트 에 반환합니다.$search쿼리 에 동시 옵션을 사용하는 경우 MongoDB Search는 쿼리 내 병렬 처리를 활성화합니다. 자세히 학습 세그먼트 간 쿼리 실행 병렬 처리를 참조하세요.
득점
MongoDB Search는 결과 설정하다 의 모든 문서 에 관련성 기반 점수를 부여합니다. 관련성 기반 점수 매기기를 통해 MongoDB Search는 가장 높은 점수부터 가장 낮은 점수 순으로 문서를 반환할 수 있습니다. MongoDB Search는 쿼리 용어가 문서 에 자주 나타나면 문서 텀 를 높이고 컬렉션 의 여러 문서에 쿼리 텀 나타나면 점수를 낮춥니다. MongoDB Search는 또한 부스트, 감쇠 또는 기타 수정 옵션을 통해 관련성 기반 기본값 점수를 사용자 지정할 수 있도록 지원합니다. 결과 점수를 사용자 지정하는 방법에 대해 자세히 학습 결과에서 문서 점수 매기기를 참조하세요.
팁
See: Learn by Watching
이 동영상에서 MongoDB Search로 쿼리를 검색하고 추적하는 방법에 대한 개요를 확인하세요. 이 동영상에서는 MongoDB Search 연산자 및 결과에서 문서의 점수를 매기는 방법 MongoDB 대해 자세히 학습 수 있습니다.
지속 시간 소요 시간: 15분
지원되는 클라이언트
다음 클라이언트를 사용하여 MongoDB Search 쿼리를 만들고 실행 수 있습니다.
쿼리 문제 해결
빈 결과 집합
mongot 오류를 반환하지 않지만 $search 쿼리가 다음과 같은 경우 빈 결과 집합을 반환합니다.
존재하지 않는 인덱스 참조합니다. 쿼리 에서 이름으로 인덱스 지정하지 않으면 MongoDB Search는 기본적으로
default라는 이름의 인덱스 사용합니다.default이라는 인덱스 없거나 지정한 인덱스 존재하지 않는 경우, MongoDB Search는 오류를 반환하지 않고 빈 결과 설정하다 반환합니다.index옵션을 사용하여 이름으로 유효한 인덱스 지정할 수 있습니다.인덱싱되지 않은 필드 지정합니다. 인덱싱되지 않은 필드 에 대해 쿼리 실행 경우 MongoDB Search는 오류를 반환하지 않고 빈 결과 설정하다 반환합니다. 인덱싱된 필드만
path매개변수의 값으로 지정해야 합니다. 컬렉션의 인덱스 정의에서 동적 매핑 을 활성화하여 컬렉션의 동적으로 인덱싱 가능한 모든 필드 가 자동으로 인덱싱되도록 할 수 있습니다. 자세한 학습 은 동적 매핑을 참조하세요.Uses the
textoperator on a field path which is not indexed as astringtype. If a field is indexed as a MongoDB Search field type other thanstring, such asstringFacetorautocomplete, MongoDB Search doesn't return an error and returns an empty result set. You must index the fields withstringBSON data type values as string type to query the fields using the text operator.
PlanExecutor 오류
mongot $search 쿼리가 다음과 같은 경우 PlanExecutor 오류를 반환합니다.
잘못된 데이터 유형 으로 인덱싱되는 필드 지정합니다. 이 경우 쿼리 실행 하면 MongoDB Search는 잘못 인덱싱된 필드 와 올바른 데이터 유형 식별하는 오류 메시지를 반환합니다. 예시 를 들면 다음과 같습니다.
PlanExecutor error during aggregation :: caused by :: Cannot facet on field "genres" because it was not indexed as a "stringFacet" field. facetstringnumberdate예시stringFacet를 들어, 또는 필드에 대해( MongoDB Search 연산자) 쿼리를 실행 하려면,number과 같은 해당 MongoDB Search 필드 유형을 사용하여 필드에 대한 인덱스date만듭니다. } 및 입니다. 자세한 학습 은 지원되는 데이터 유형과 지원되지 않는 데이터 유형을 참조하세요.