diff --git a/pymongo/operations.py b/pymongo/operations.py index 58655753b..4872afa91 100644 --- a/pymongo/operations.py +++ b/pymongo/operations.py @@ -592,7 +592,7 @@ class SearchIndexModel: self, definition: Mapping[str, Any], name: Optional[str] = None, - type: Optional[str] = "search", + type: Optional[str] = None, **kwargs: Any, ) -> None: """Create a Search Index instance. @@ -613,7 +613,8 @@ class SearchIndexModel: if name is not None: self.__document["name"] = name self.__document["definition"] = definition - self.__document["type"] = type + if type is not None: + self.__document["type"] = type self.__document.update(kwargs) @property diff --git a/test/test_index_management.py b/test/test_index_management.py index c47cffa75..5b6653dcb 100644 --- a/test/test_index_management.py +++ b/test/test_index_management.py @@ -62,7 +62,17 @@ class TestCreateSearchIndex(IntegrationTest): listener.reset() with self.assertRaises(OperationFailure): coll.create_search_index({"definition": definition, "arbitraryOption": 1}) - self.assertIn("arbitraryOption", listener.events[0].command["indexes"][0]) + self.assertEqual( + {"definition": definition, "arbitraryOption": 1}, + listener.events[0].command["indexes"][0], + ) + + listener.reset() + with self.assertRaises(OperationFailure): + coll.create_search_index({"definition": definition, "type": "search"}) + self.assertEqual( + {"definition": definition, "type": "search"}, listener.events[0].command["indexes"][0] + ) class SearchIndexIntegrationBase(unittest.TestCase):