def test_multi_threading_update(self):
        """Test that we can update documents in multiple threads."""
        original_document = {
            "text_field": "text field",
            "text_field_filter": "text field filter",
            "text_field_lexical": "text field lexical",
            "text_field_tensor": "text field tensor",
            "int_field": 1,
            "int_field_filter": 2,
            "int_field_score_modifier": 3,
            "float_field": 1.1,
            "float_field_filter": 2.2,
            "bool_field_filter": True,
            "_id": "1"
        }
        self.client.index(self.update_doc_index_name).add_documents(documents=[original_document])
        self.assertEqual(1, self.client.index(self.update_doc_index_name).get_stats()["numberOfDocuments"])

        def randomly_update_document(number_of_updates: int = 50):
            updating_fields_pools = {"text_field", "text_field_filter", "text_field_lexical",
                                     "int_field", "int_field_filter", "int_field_score_modifier", "float_field",
                                     "float_field_filter", "bool_field_filter"}

            for _ in range(number_of_updates):
                picked_fields = random.sample(updating_fields_pools, 3)
                updated_doc = {"_id": "1"}
                for picked_field in picked_fields:
                    if picked_field.startswith("text_field"):
                        updated_doc[picked_field] = "text field" + str(random.randint(1, 100))
                    elif picked_field.startswith("int_field"):
                        updated_doc[picked_field] = np.random.randint(1, 100)
                    elif picked_field.startswith("float_field"):
                        updated_doc[picked_field] = np.random.uniform(1, 100)
                    elif picked_field.startswith("bool_field"):
                        updated_doc[picked_field] = bool(random.getrandbits(1))

                self.client.index(self.update_doc_index_name).update_documents(documents=[updated_doc])

        number_of_threads = 10
        updates_per_thread = 50

        threads = [threading.Thread(target=randomly_update_document, args=(updates_per_thread,)) for _ in
                   range(number_of_threads)]

        for thread in threads:
            thread.start()

        for thread in threads:
            thread.join()

        updated_doc = self.client.index(self.update_doc_index_name).get_document("1")

        # Assertions to ensure the document is not broken after the update
        self.assertEqual(1, self.client.index(self.update_doc_index_name).get_stats()["numberOfDocuments"])
        self.assertTrue(updated_doc["text_field"].startswith("text field"))
        self.assertTrue(updated_doc["text_field_filter"].startswith("text field"))
        self.assertTrue(updated_doc["text_field_lexical"].startswith("text field"))
        self.assertTrue(updated_doc["text_field_tensor"].startswith("text field"))
        self.assertTrue(1 <= updated_doc["int_field"] <= 100)
        self.assertTrue(1 <= updated_doc["int_field_filter"] <= 100)
        self.assertTrue(1 <= updated_doc["int_field_score_modifier"] <= 100)
        self.assertTrue(1 <= updated_doc["float_field"] <= 100)
        self.assertTrue(1 <= updated_doc["float_field_filter"] <= 100)
        self.assertTrue(isinstance(updated_doc["bool_field_filter"], bool))
Test that we can update documents in multiple threads.
tests/api_tests/v1/tests/api_tests/structured_index/test_partial_update_document.py