Docs Menu

Docs Home애플리케이션 개발Python 드라이버PyMongo

Atlas search 인덱스

이 페이지의 내용

  • 개요
  • 검색 인덱스 만들기
  • 검색 인덱스 나열
  • 검색 인덱스 업데이트
  • 검색 인덱스 삭제

Atlas Search 기능을 사용하면 MongoDB Atlas에서 호스팅되는 컬렉션에서 전체 텍스트 검색을 수행할 수 있습니다. 인덱스는 검색 동작과 인덱싱할 필드를 지정합니다.

MongoDB Atlas Atlas Search에 대해 자세히 알아보려면 Atlas Search 인덱스 문서를 참조하세요.

컬렉션에서 다음과 같은 메서드를 호출하여 Atlas Search 인덱스를 관리할 수 있습니다.

  • create_search_index()

  • create_search_indexes()

  • list_search_indexes()

  • update_search_index()

  • drop_search_index()

참고

Atlas 검색 인덱스 관리 방법은 비동기적으로 실행됩니다. 드라이버 메서드는 성공적으로 실행되었는지 확인하기 전에 반환될 수 있습니다. 인덱스의 현재 상태를 확인하려면 list_search_indexes() 메서드를 호출합니다.

다음 섹션에서는 코드 예시를 제공하여 이전의 각 메서드를 사용하는 방법을 보여줍니다.

create_search_index()create_search_indexes() 메서드를 사용하여 Atlas Search 인덱스를 생성합니다.

다음 코드 예시에서는 단일 인덱스를 생성하는 방법을 보여줍니다.

index = {
"definition": {
"mappings": {
"dynamic": True
}
},
"name": "<index name>",
}
collection.create_search_index(index)

다음 코드 예시에서는 여러 인덱스를 생성하는 방법을 보여줍니다.

index_one = {
"definition": {
"mappings": {
"dynamic": True
}
},
"name": "my_index",
}
index_two = {
"definition": {
"mappings": {
"dynamic": True
}
},
"name": "my_other_index",
}
indexes = [index_one, index_two]
collection.create_search_indexes(models=indexes)

list_search_indexes() 메서드를 사용하여 컬렉션의 Atlas Search 인덱스를 반환합니다.

다음 코드 예시에서는 컬렉션의 검색 인덱스 목록을 출력하는 방법을 보여줍니다.

results = list(collection.list_search_indexes())
for index in results:
print(index)

update_search_index() 메서드를 사용하여 Atlas Search 인덱스를 업데이트합니다.

다음 코드에서는 검색 업인덱스를데이트하는 방법을 보여줍니다.

new_index = {
"definition": {
"mappings": {
"dynamic": True
}
},
"name": "my_new_index",
}
collection.update_search_index("my_index", new_index)

drop_search_index() 메서드를 사용하여 Atlas Search 인덱스를 제거합니다.

다음 코드에서는 컬렉션에서 검색 인덱스를 삭제하는 방법을 보여줍니다.

collection.drop_index("my_index")
← Multikey Indexes