Skip to content

Commit

Permalink
DOCSP-33429: atlas search idx mgmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir committed Jan 12, 2024
1 parent f474093 commit fba8137
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 422 deletions.
462 changes: 48 additions & 414 deletions examples/src/test/kotlin/SearchIndexesTest.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
moviesCollection.dropSearchIndex("myIndex");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val searchIndexesList = moviesCollection.listSearchIndexes().toList()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
val indexOne = SearchIndexModel(
"myIndex1",
Document("analyzer", "lucene.standard").append(
"mappings", Document("dynamic", true)
)
)

val indexTwo = SearchIndexModel(
"myIndex2",
Document("analyzer", "lucene.simple").append(
"mappings", Document("dynamic", true)
)
)

val resultCreateIndexes = moviesCollection.createSearchIndexes(listOf(indexOne, indexTwo))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
val index = Document(
"mappings",
Document("dynamic", true)
)
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index)
println("Index created: $resultCreateIndex")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
moviesCollection.updateSearchIndex(
"myIndex",
Document("analyzer", "lucene.simple").append(
"mappings",
Document("dynamic", false)
.append(
"fields",
Document(
"title",
Document("type", "string")
)
)
)
)
25 changes: 17 additions & 8 deletions source/fundamentals/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,45 +254,50 @@ methods to create Atlas Search indexes.

The following code example shows how to create a single index:


.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt
:language: kotlin

The following code example shows how to create multiple indexes:


.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt
:language: kotlin

List Search Indexes
+++++++++++++++++++

You can use the
`listSearchIndexes() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#listSearchIndexes()>`__
`listSearchIndexes() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/list-search-indexes.html>`__
method to return the Atlas Search indexes of a collection.

The following code example shows how to print a list of the search indexes of
a collection:


.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.list-search-indexes.kt
:language: kotlin

Update a Search Index
+++++++++++++++++++++

You can use the
`updateSearchIndex() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#updateSearchIndex(java.lang.String,org.bson.conversions.Bson)>`__
`updateSearchIndex() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/update-search-index.html>`__
method to update an Atlas Search index.

The following code shows how to update a search index:


.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.update-search-indexes.kt
:language: kotlin

Drop a Search Index
+++++++++++++++++++

You can use the
`dropSearchIndex() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#dropSearchIndex(java.lang.String)>`__
`dropSearchIndex() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/drop-search-index.html>`__
method to remove an Atlas Search index.

The following code shows how to delete a search index from a collection:


.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.drop-search-index.kt
:language: kotlin

.. _text-indexes:

Expand Down Expand Up @@ -408,6 +413,10 @@ The following example creates a ``2dsphere`` index on the ``location.geo`` field

Index created: location.geo_2dsphere

.. important::

Attempting to create a geospatial index on a field that is covered by a geospatial index results in an error.

The following is an example of a geospatial query that is covered by the index
created in the preceding code snippet:

Expand Down

0 comments on commit fba8137

Please sign in to comment.