인덱스 정의에서 multi 객체를 사용하여 필드를 인덱싱하는 데 사용할 대체 분석기를 지정할 수 있습니다. 기본 분석기 외에 대체 분석기를 사용하여 필드를 인덱싱하는 경우 기본 분석기 또는 대체 분석기로 컬렉션을 검색할 수 있습니다. 이 페이지에서는 multi를 사용하여 인덱스 정의에 대체 분석기를 지정하는 방법을 보여줍니다.
멀티 분석기 제한 사항
multi경로 옵션은 문자열 유형의 필드에만 사용할 수 있습니다.
MongoDB Search는 multi 객체의 여러 계층 중첩을 지원 하지 않습니다.
예시
다음 예에서는 sample_mflix.movies 컬렉션 의 필드에 대한 인덱스 정의를 보여 줍니다. 클러스터 에 컬렉션 로드하는 경우, Atlas UI 의 비주얼 편집기 또는 JSON 편집기를 사용하거나 mongosh을(를) 사용하여 예시 인덱스를 만들 수 있습니다.
➤ 언어 선택 드롭다운 메뉴를 사용하여 이 페이지의 예시에 대한 인터페이스를 설정하다.
단일 필드 예시
다음 예시 인덱스 정의는 standard 분석기를 사용하여 title 필드에 대한 인덱스를 지정합니다. 또한 인덱스 정의에서는 lucene.french 분석기를 title 필드의 대체 분석기로 지정합니다(이름은 frenchAnalyzer).
인덱스를 구성하려면 Refine Your Index를 클릭합니다.
Field Mappings 섹션에서 Add Field 을 클릭하여 Add Field Mapping창을 엽니다.
Field Name 드롭다운 메뉴에서
title을(를) 선택합니다.Data Type 드롭다운을 클릭하고 아직 선택되지 않은 경우 String을(를) 선택합니다.
String Properties을 확장하고 다음과 같이 변경합니다:
인덱스 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.standard을(를) 선택합니다.검색 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.standard을(를) 선택합니다.인덱스 옵션
기본값
offsets을(를) 사용합니다.Store
기본값
true을(를) 사용합니다.위 내용 무시
기본 설정을 유지합니다.
규범
기본값
include을(를) 사용합니다.title필드에 다른 분석기를 구성하려면 Add Multi Field 을 클릭합니다.Multi Field Name 필드에
frenchAnalyzer을 입력합니다.다음과 같이 Multi Field Properties 을 변경합니다:
인덱스 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.french을(를) 선택합니다.검색 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.french을(를) 선택합니다.인덱스 옵션
기본값
offsets을(를) 사용합니다.Store
기본값
true을(를) 사용합니다.위 내용 무시
기본 설정을 유지합니다.
규범
기본값
include을(를) 사용합니다.Add를 클릭합니다.
Save Changes를 클릭합니다.
Create Search Index를 클릭합니다.
기본 인덱스 정의를 다음 인덱스 정의로 바꾸세요.
1 { 2 "mappings": { 3 "dynamic": false, 4 "fields": { 5 "title": { 6 "type": "string", 7 "analyzer": "lucene.standard", 8 "multi": { 9 "frenchAnalyzer": { 10 "type": "string", 11 "analyzer": "lucene.french" 12 } 13 } 14 } 15 } 16 } 17 } Next를 클릭합니다.
Create Search Index를 클릭합니다.
1 db.movies.createSearchIndex( 2 "default", 3 { 4 "mappings": { 5 "dynamic": false, 6 "fields": { 7 "title": { 8 "type": "string", 9 "analyzer": "lucene.standard", 10 "multi": { 11 "frenchAnalyzer": { 12 "type": "string", 13 "analyzer": "lucene.french" 14 } 15 } 16 } 17 } 18 } 19 } 20 )
다음 쿼리는 frenchAnalyzer라는 대체 분석기를 사용하여 문자열 liberte를 검색합니다.
인덱스 의 Query 버튼을 클릭합니다.
쿼리 편집하려면 Edit Query 을(를) 클릭합니다.
쿼리 줄에서 을 클릭하고 데이터베이스 와 컬렉션 선택합니다.
기본값 쿼리 다음으로 바꾸고 Find을 클릭합니다.
[ { "$search": { "text": { "query": "liberte", "path": { "value": "title", "multi": "frenchAnalyzer" } } } } ] SCORE: 4.9305267333984375 _id: "573a1392f29313caabcd9950" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) fullplot: "A famous left-wing satirical comedy about two ex-convicts, one of whom…" genres: Array (2) imdb: Object languages: Array (1) lastupdated: "2015-08-21 00:02:36.330000000" num_mflix_comments: 1 plot: "A famous left-wing satirical comedy about two ex-convicts, one of whom…" poster: "https://m.media-amazon.com/images/M/MV5BODg0ODAzNTItM2M4ZC00NGYxLWIzMm…" rated: "APPROVED" released: 1931-12-31T00:00:00.000+00:00 runtime: 97 title: "è Nous la Libertè" tomatoes: Object type: "movie" writers: Array (1) year: 1931
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 "query": "liberte", 6 "path": { "value": "title", "multi": "frenchAnalyzer" } 7 } 8 } 9 }, 10 { 11 "$project": { 12 "title": 1, 13 "year": 1, 14 "_id": 0 15 } 16 } 17 ])
[ { title: 'è Nous la Libertè', year: 1931 } ]
frenchAnalyzer 이(가) 인덱싱된 문자열 è Nous la Libertè 와 쿼리 텀 liberte 를 모두 기본 단어 libert(으)로 축소했기 때문에 결과에 있는 문서 일치하는 것입니다. MongoDB Search는 standard 분석기 사용한 검색 에 대해 분음 부호를 제거 하지 않으므로 이 문서 반환하지 않습니다. 각 분석기 인덱스 및 쿼리 에 대해 다음과 같은 토큰(검색 가능한 용어)을 생성합니다.
분석기 | Index Tokens | 쿼리 토큰 |
|---|---|---|
표준 분석기 |
|
|
프랑스어 분석기 |
|
|
여러 필드 예시
다음 예시 인덱스 정의는 standard 분석기를 사용하여 title 및 plot 필드에 대한 인덱스를 지정합니다. 인덱스 정의는 또한 title 및 plot 필드에 대한 대체 분석기로 lucene.french를 지정합니다.
인덱스를 구성하려면 Refine Your Index을(를) 클릭합니다.
Field Mappings 섹션에서 Add Field 을 클릭하여 Add Field Mapping창을 엽니다.
Field Name 드롭다운 메뉴에서
title을(를) 선택합니다.Data Type 드롭다운을 클릭하고 아직 선택되지 않은 경우 String을(를) 선택합니다.
String Properties을 확장하고 다음과 같이 변경합니다:
인덱스 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.standard을(를) 선택합니다.검색 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.standard을(를) 선택합니다.인덱스 옵션
기본값
offsets을(를) 사용합니다.Store
기본값
true을(를) 사용합니다.위 내용 무시
기본 설정을 유지합니다.
규범
기본값
include을(를) 사용합니다.title필드에 다른 분석기를 구성하려면 Add Multi Field 을 클릭합니다.Multi Field Name 필드에
frenchAnalyzer을 입력합니다.다음과 같이 Multi Field Properties 을 변경합니다:
인덱스 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.french을(를) 선택합니다.검색 분석기
아직 선택되지 않은 경우 드롭다운에서
lucene.french을(를) 선택합니다.인덱스 옵션
기본값
offsets을(를) 사용합니다.Store
기본값
true을(를) 사용합니다.위 내용 무시
기본 설정을 유지합니다.
규범
기본값
include을(를) 사용합니다.Add를 클릭합니다.
Add Field Mapping 을 클릭하여 Add Field Mapping 창을 엽니다.
Field Name 드롭다운 메뉴에서
plot을(를) 선택합니다.4부터 9까지 단계를 반복합니다.
Save Changes를 클릭합니다.
Create Search Index를 클릭합니다.
기본 인덱스 정의를 다음 인덱스 정의로 바꾸세요.
1 { 2 "mappings": { 3 "dynamic": false, 4 "fields": { 5 "title": { 6 "type": "string", 7 "analyzer": "lucene.standard", 8 "multi": { 9 "frenchAnalyzer": { 10 "type": "string", 11 "analyzer": "lucene.french" 12 } 13 } 14 }, 15 "plot": { 16 "type": "string", 17 "analyzer": "lucene.standard", 18 "multi": { 19 "frenchAnalyzer": { 20 "type": "string", 21 "analyzer": "lucene.french" 22 } 23 } 24 } 25 } 26 } 27 } Next를 클릭합니다.
Create Search Index를 클릭합니다.
1 db.movies.createSearchIndex( 2 "default", 3 { 4 "mappings": { 5 "dynamic": false, 6 "fields": { 7 "title": { 8 "type": "string", 9 "analyzer": "lucene.standard", 10 "multi": { 11 "frenchAnalyzer": { 12 "type": "string", 13 "analyzer": "lucene.french" 14 } 15 } 16 }, 17 "plot": { 18 "type": "string", 19 "analyzer": "lucene.standard", 20 "multi": { 21 "frenchAnalyzer": { 22 "type": "string", 23 "analyzer": "lucene.french" 24 } 25 } 26 } 27 } 28 } 29 } 30 )
다음 쿼리는 frenchAnalyzer라는 대체 분석기를 사용하여 title 및 plot 필드에서 revolution 문자열과 일치하는 항목을 검색합니다.
인덱스 의 Query 버튼을 클릭합니다.
쿼리 편집하려면 Edit Query 을(를) 클릭합니다.
쿼리 줄에서 을 클릭하고 데이터베이스 와 컬렉션 선택합니다.
기본값 쿼리 다음으로 바꾸고 Find을 클릭합니다.
[ { "$search": { "text": { "query": "revolution", "path": [ "title", "plot", { "value": "title", "multi": "frenchAnalyzer" }, { "value": "plot", "multi": "frenchAnalyzer" } ] } } } ] SCORE: 14.07243537902832 _id: "573a13dbf29313caabdaf845" awards: Object cast: Array (4) countries: Array (11) directors: Array (1) fullplot: "REVOLUTION is a film about changing the world, going for it, taking a …" genres: Array (3) imdb: Object languages: Array (1) lastupdated: "2015-07-09 11:14:18.300000000" metacritic: 53 num_mflix_comments: 0 plot: "REVOLUTION is a film about changing the world, going for it, taking a …" poster: "https://m.media-amazon.com/images/M/MV5BMTc1NDIxNjc0N15BMl5BanBnXkFtZT…" rated: "PG" released: 2015-04-22T00:00:00.000+00:00 runtime: 85 title: "Revolution" tomatoes: Object type: "movie" writers: Array (1) year: 2012 SCORE: 13.935744285583496 _id: "573a1398f29313caabce9ae2" awards: Object cast: Array (4) countries: Array (2) directors: Array (1) fullplot: "New York trapper Tom Dobb becomes an unwilling participant in the Amer…" genres: Array (3) imdb: Object languages: Array (1) lastupdated: "2015-08-14 00:46:28.990000000" num_mflix_comments: 1 plot: "New York trapper Tom Dobb becomes an unwilling participant in the Amer…" poster: "https://m.media-amazon.com/images/M/MV5BZmZhMmEyNjktZTgxZC00NzQyLTkyZD…" rated: "PG-13" released: 1985-12-25T00:00:00.000+00:00 runtime: 126 title: "Revolution" type: "movie" writers: Array (1) year: 1985 SCORE: 11.623137474060059 _id: "573a13f5f29313caabde37d4" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) fullplot: "Together with five Soviet avant-garde artists, hero of the Russian rev…" genres: Array (1) imdb: Object languages: Array (1) lastupdated: "2015-09-15 03:33:53.177000000" num_mflix_comments: 1 plot: "Together with five Soviet avant-garde artists, hero of the Russian rev…" released: 2014-11-18T00:00:00.000+00:00 runtime: 113 title: "Angels of Revolution" type: "movie" writers: Array (3) year: 2014 SCORE: 11.210482597351074 _id: "573a1396f29313caabce4248" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) fullplot: "An account of the adventures of two sets of identical twins, badly scr…" genres: Array (2) imdb: Object languages: Array (1) lastupdated: "2015-09-05 00:50:08.277000000" num_mflix_comments: 0 plot: "Two mismatched sets of identical twins - one aristocrat, one peasant -…" poster: "https://m.media-amazon.com/images/M/MV5BODM2MzE3NmMtNmE2ZS00OGI2LWI5NT…" rated: "M" released: 1970-08-14T00:00:00.000+00:00 runtime: 90 title: "Start the Revolution Without Me" tomatoes: Object type: "movie" writers: Array (2) year: 1970 SCORE: 8.332647323608398 _id: "573a1398f29313caabceba10" awards: Object cast: Array (4) countries: Array (5) directors: Array (2) fullplot: "A history of the French Revolution from the decision of the king to co…" genres: Array (3) imdb: Object languages: Array (2) lastupdated: "2015-09-05 00:30:36.643000000" num_mflix_comments: 0 plot: "A history of the French Revolution from the decision of the king to co…" released: 1989-10-25T00:00:00.000+00:00 runtime: 360 title: "La rèvolution franèaise" tomatoes: Object type: "movie" writers: Array (5) year: 1989 SCORE: 7.699893474578857 _id: "573a13a4f29313caabd10215" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) genres: Array (1) imdb: Object languages: Array (1) lastupdated: "2015-09-10 17:19:25.853000000" metacritic: 63 num_mflix_comments: 0 poster: "https://m.media-amazon.com/images/M/MV5BMTkxOTUzNjg0Ml5BMl5BanBnXkFtZT…" released: 2001-04-22T00:00:00.000+00:00 runtime: 90 title: "Revolution #9" tomatoes: Object type: "movie" writers: Array (1) year: 2001 SCORE: 6.8415961265563965 _id: "573a13a0f29313caabd05edb" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) fullplot: "Friendship and betrayal between two poets during the French Revolution…" genres: Array (2) imdb: Object languages: Array (1) lastupdated: "2015-04-17 01:56:58.940000000" metacritic: 60 num_mflix_comments: 0 plot: "Friendship and betrayal between two poets during the French Revolution…" poster: "https://m.media-amazon.com/images/M/MV5BMTQ0Nzc0OTkwM15BMl5BanBnXkFtZT…" rated: "PG-13" released: 2001-04-18T00:00:00.000+00:00 runtime: 124 title: "Pandaemonium" tomatoes: Object type: "movie" writers: Array (1) year: 2000 SCORE: 6.7074995040893555 _id: "573a1397f29313caabce8972" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) fullplot: "Set ten years after the most peaceful revolution in United States hist…" genres: Array (3) imdb: Object languages: Array (1) lastupdated: "2015-09-10 17:14:53.427000000" num_mflix_comments: 1 plot: "Set ten years after the most peaceful revolution in United States hist…" poster: "https://m.media-amazon.com/images/M/MV5BYTE5MGNhN2QtMTNhYy00MDQ1LTgzOT…" released: 1983-11-03T00:00:00.000+00:00 runtime: 80 title: "Born in Flames" tomatoes: Object type: "movie" writers: Array (2) year: 1983 SCORE: 6.615457057952881 _id: "573a1395f29313caabce1c90" awards: Object cast: Array (4) countries: Array (1) directors: Array (1) fullplot: "The study of a youth on the edge of adulthood and his aunt, ten years …" genres: Array (2) imdb: Object languages: Array (1) lastupdated: "2015-08-21 00:16:07.580000000" num_mflix_comments: 0 plot: "The study of a youth on the edge of adulthood and his aunt, ten years …" poster: "https://m.media-amazon.com/images/M/MV5BMmJjOGRjNWMtOGE5Ni00YzYwLThkM2…" released: 1964-05-12T00:00:00.000+00:00 runtime: 105 title: "Before the Revolution" tomatoes: Object type: "movie" writers: Array (2) year: 1964 SCORE: 6.615457057952881 _id: "573a13cef29313caabd86ecc" awards: Object cast: Array (1) countries: Array (1) directors: Array (1) fullplot: "Through intimate interviews, provocative art, and rare, historical fil…" genres: Array (1) imdb: Object languages: Array (1) lastupdated: "2015-04-02 00:54:39.997000000" metacritic: 70 num_mflix_comments: 1 plot: "Through intimate interviews, provocative art, and rare, historical fil…" poster: "https://m.media-amazon.com/images/M/MV5BMjE1MDU1MDA2Nl5BMl5BanBnXkFtZT…" released: 2011-06-01T00:00:00.000+00:00 runtime: 83 title: "!Women Art Revolution" tomatoes: Object type: "movie" year: 2010
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 "query": "revolution", 6 "path": ["title", "plot", 7 { "value": "title", "multi": "frenchAnalyzer" }, 8 { "value": "plot", "multi": "frenchAnalyzer" } 9 ] 10 } 11 } 12 }, 13 { 14 "$limit": 5 15 }, 16 { 17 "$project": { 18 "title": 1, 19 "plot": 1, 20 "year": 1, 21 "_id": 0 22 } 23 } 24 ])
[ { year: 2012, plot: 'REVOLUTION is a film about changing the world, going for it, taking a stand, and fighting for something. A true-life adventure following Director, Rob Stewart (SHARKWATER) over four years ...', title: 'Revolution' }, { plot: 'New York trapper Tom Dobb becomes an unwilling participant in the American Revolution after his son Ned is drafted into the Army by the villainous Sergeant Major Peasy. Tom attempts to find...', title: 'Revolution', year: 1985 }, { plot: "Together with five Soviet avant-garde artists, hero of the Russian revolution Polina Schneider travels to Siberia to 'civilize' the native Khanty and Nenets tribes, for whom interaction ...", title: 'Angels of Revolution', year: 2014 }, { plot: 'Two mismatched sets of identical twins - one aristocrat, one peasant - mistakenly exchange identities on the eve of the French Revolution.', title: 'Start the Revolution Without Me', year: 1970 }, { plot: "A history of the French Revolution from the decision of the king to convene the Etats-Generaux in 1789 in order to deal with France's debt problem. The first part of the movie tells the ...", title: 'La rèvolution franèaise', year: 1989 } ]
결과의 문서에는 title 및 plot 필드 모두에 쿼리 텀이 포함되어 있습니다. 각 분석기는 결과의 각 문서의 title 필드에 대해 다음 토큰(검색 가능한 텀)을 생성합니다.
년 | 분석기 | Index Tokens | 쿼리 토큰 |
2012 | Standard Analyzer French Analyzer | revolutionrevolution | revolutionrevolution |
1985 | Standard Analyzer French Analyzer | revolutionrevolution | revolutionrevolution |
2014 | Standard Analyzer French Analyzer | angels, of, revolutionangels, of, revolution | revolutionrevolution |
1970 | Standard Analyzer French Analyzer | start, the, revolution, without, mestart, the, revolution, without | revolutionrevolution |
1989 | Standard Analyzer French Analyzer | la, rèvolution, franèaiserevolution, franeais | revolutionrevolution |
결과의 다섯 번째 문서에서 frenchAnalyzer는 title 필드의 발음 구별 기호를 제거하여 쿼리 텀과 일치하는 문서를 찾습니다.