멀티 분석기
인덱스 정의에서 multi
객체를 사용하여 필드를 인덱싱하는 데 사용할 대체 분석기를 지정할 수 있습니다. 기본 분석기 외에 대체 분석기를 사용하여 필드를 인덱스하는 경우 기본 분석기 또는 대체 분석기로 컬렉션을 검색할 수 있습니다. 이 페이지에서는 multi
를 사용하여 인덱스 정의에 대체 분석기를 지정하는 방법을 보여줍니다. 대체 분석기를 사용한 검색에 대해 자세히 알아보려면 쿼리 경로 구성을 참조하세요.
제한 사항
multi
경로 옵션은 문자열 유형의 필드에만 사용할 수 있습니다.
Atlas Search는 multi
객체의 다중 계층 중첩을 지원하지 않습니다.
예시
다음 예에서는 컬렉션 의 필드에 대한 인덱스 정의를 보여 sample_mflix.movies
줍니다. 클러스터 에 컬렉션 로드하는 경우, Atlas UI 의 비주얼 편집기 또는 JSON 편집기를 사용하여 예시 인덱스를 만들 수 있습니다. 원하는 구성 방법을 선택한 후 데이터베이스 와 컬렉션 선택하여 인덱스 정의합니다.
단일 필드 예제
다음 예시 인덱스 정의는 title
standard
분석기 사용하여 필드 에 대한 인덱스 지정합니다. 또한 인덱스 정의는 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를 클릭합니다.
다음 쿼리 frenchAnalyzer
이라는 대체 분석기 사용하여 liberte
문자열을 검색 .
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
(으)로 축소했기 때문에 결과에 있는 문서 일치하는 것입니다. Atlas Search standard
분석기 사용한 검색 에 대해 분음 부호를 제거 하지 않으므로 이 문서 반환하지 않습니다. 각 분석기 인덱스 및 쿼리 에 대해 다음과 같은 토큰(검색 가능한 용어)을 생성합니다.
분석기 | Index Tokens | 쿼리 토큰 |
---|---|---|
표준 분석기 |
|
|
프랑스어 분석기 |
|
|
여러 필드 예제
다음 예시 인덱스 정의는 분석기 title
plot
사용하여 및 standard
필드에 인덱스 지정합니다. 또한 인덱스 정의는 및 필드에 대한 대체 분석기 로 lucene.french를 title
plot
지정합니다.
인덱스를 구성하려면 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를 클릭합니다.
다음 쿼리 frenchAnalyzer
이라는 대체 분석기 사용하여 title
및 plot
필드에서 문자열 revolution
과 일치하는 항목을 검색합니다.
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 | revolution revolution | revolution revolution |
1985 | Standard Analyzer French Analyzer | revolution revolution | revolution revolution |
2014 | Standard Analyzer French Analyzer | angels , of , revolution angels , of , revolution | revolution revolution |
1970 | Standard Analyzer French Analyzer | start , the , revolution , without , me start , the , revolution , without | revolution revolution |
1989 | Standard Analyzer French Analyzer | la , rèvolution , franèaise revolution , franeais | revolution revolution |
결과의 다섯 번째 문서 의 경우 frenchAnalyzer
는 title
필드 에서 발음 부호를 제거하여 문서 쿼리 텀 와 일치시킵니다.