|
| 1 | +.. _kotlin-sync-atlas-search-index: |
| 2 | + |
| 3 | +==================== |
| 4 | +Atlas Search Indexes |
| 5 | +==================== |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +.. facet:: |
| 14 | + :name: genre |
| 15 | + :values: reference |
| 16 | + |
| 17 | +.. meta:: |
| 18 | + :keywords: index, query, optimization, efficiency |
| 19 | + |
| 20 | +Overview |
| 21 | +-------- |
| 22 | + |
| 23 | +:atlas:`Atlas Search </atlas-search>` enables you to perform full-text searches on |
| 24 | +collections hosted on MongoDB Atlas. Atlas Search indexes specify the behavior of |
| 25 | +the search and which fields to index. |
| 26 | + |
| 27 | +You can call the following methods on a collection to manage your Atlas Search |
| 28 | +indexes: |
| 29 | + |
| 30 | +- ``createSearchIndex()`` |
| 31 | +- ``createSearchIndexes()`` |
| 32 | +- ``listSearchIndexes()`` |
| 33 | +- ``updateSearchIndex()`` |
| 34 | +- ``dropSearchIndex()`` |
| 35 | + |
| 36 | +.. note:: |
| 37 | + |
| 38 | + The Atlas Search index management methods run asynchronously, and might return before |
| 39 | + confirming that they ran successfully. To determine the current status of the indexes, |
| 40 | + call the ``listSearchIndexes()`` method. |
| 41 | + |
| 42 | +The following sections provide code examples that demonstrate how to use |
| 43 | +each of the preceding methods. |
| 44 | + |
| 45 | +.. _kotlin-sync-atlas-search-index-create: |
| 46 | + |
| 47 | +Create a Search Index |
| 48 | +--------------------- |
| 49 | + |
| 50 | +You can use the `createSearchIndex() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/create-search-index.html>`__ |
| 51 | +and the `createSearchIndexes() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/create-search-indexes.html>`__ |
| 52 | +methods to create one or more Atlas Search indexes. |
| 53 | + |
| 54 | +The following code example shows how to create a single index: |
| 55 | + |
| 56 | +.. literalinclude:: /includes/indexes/indexes.kt |
| 57 | + :language: kotlin |
| 58 | + :start-after: start-create-search-index |
| 59 | + :end-before: end-create-search-index |
| 60 | + :dedent: |
| 61 | + |
| 62 | +The following code example shows how to create multiple indexes: |
| 63 | + |
| 64 | +.. literalinclude:: /includes/indexes/indexes.kt |
| 65 | + :language: kotlin |
| 66 | + :start-after: start-create-search-indexes |
| 67 | + :end-before: end-create-search-indexes |
| 68 | + :dedent: |
| 69 | + |
| 70 | +To learn more about the syntax used to define Atlas Search indexes, see the |
| 71 | +:atlas:`Review Atlas Search Index Syntax </atlas-search/index-definitions>` guide |
| 72 | +in the Atlas manual. |
| 73 | + |
| 74 | +.. _kotlin-sync-atlas-search-index-list: |
| 75 | + |
| 76 | +List Search Indexes |
| 77 | +------------------- |
| 78 | + |
| 79 | +You can use the |
| 80 | +`listSearchIndexes() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/list-search-indexes.html>`__ |
| 81 | +method to return all Atlas Search indexes in a collection. |
| 82 | + |
| 83 | +The following code example shows how to print a list of the search indexes in |
| 84 | +a collection: |
| 85 | + |
| 86 | +.. literalinclude:: /includes/indexes/indexes.kt |
| 87 | + :language: kotlin |
| 88 | + :start-after: start-list-search-indexes |
| 89 | + :end-before: end-list-search-indexes |
| 90 | + :dedent: |
| 91 | + |
| 92 | +.. _kotlin-sync-atlas-search-index-update: |
| 93 | + |
| 94 | +Update a Search Index |
| 95 | +--------------------- |
| 96 | + |
| 97 | +You can use the |
| 98 | +`updateSearchIndex() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/update-search-index.html>`__ |
| 99 | +method to update an Atlas Search index. |
| 100 | + |
| 101 | +The following code shows how to update a search index: |
| 102 | + |
| 103 | +.. literalinclude:: /includes/indexes/indexes.kt |
| 104 | + :language: kotlin |
| 105 | + :start-after: start-update-search-indexes |
| 106 | + :end-before: end-update-search-indexes |
| 107 | + :dedent: |
| 108 | + |
| 109 | +.. _kotlin-sync-atlas-search-index-drop: |
| 110 | + |
| 111 | +Delete a Search Index |
| 112 | +--------------------- |
| 113 | + |
| 114 | +You can use the |
| 115 | +`dropSearchIndex() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/drop-search-index.html>`__ |
| 116 | +method to delete an Atlas Search index. |
| 117 | + |
| 118 | +The following code shows how to delete a search index from a collection: |
| 119 | + |
| 120 | +.. literalinclude:: /includes/indexes/indexes.kt |
| 121 | + :language: kotlin |
| 122 | + :start-after: start-drop-search-index |
| 123 | + :end-before: end-drop-search-index |
| 124 | + :dedent: |
| 125 | + |
| 126 | +Additional Information |
| 127 | +---------------------- |
| 128 | + |
| 129 | +To learn more about MongoDB Atlas Search, see the :atlas:`Atlas Search Indexes </atlas-search/atlas-search-overview/>` |
| 130 | +documentation. |
0 commit comments