Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Don't validate the id field.

Kishore Nallan614f7a9f61d7
diff --git a/src/index.cpp b/src/index.cpp
index b2a9ab5a..43a0b9e6 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -311,6 +311,10 @@ Option<uint32_t> Index::validate_index_in_memory(nlohmann::json& document, uint3
const std::string& field_name = field_pair.first;
const field& a_field = field_pair.second;
+ if(field_name == "id") {
+ continue;
+ }
+
if((a_field.optional || op == UPDATE) && document.count(field_name) == 0) {
continue;
}
diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cpp
index 6ce707a6..5d9ad008 100644
--- a/test/collection_specific_test.cpp
+++ b/test/collection_specific_test.cpp
@@ -294,6 +294,24 @@ TEST_F(CollectionSpecificTest, PrefixWithTypos2) {
collectionManager.drop_collection("coll1");
}
+TEST_F(CollectionSpecificTest, ImportDocumentWithIntegerID) {
+ std::vector<field> fields = {field("title", field_types::STRING, false),
+ field("points", field_types::INT32, false),};
+
+ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
+
+ nlohmann::json doc1;
+ doc1["id"] = 100;
+ doc1["title"] = "East India House on Wednesday evening";
+ doc1["points"] = 100;
+
+ auto add_op = coll1->add(doc1.dump());
+ ASSERT_FALSE(add_op.ok());
+ ASSERT_EQ("Document's `id` field should be a string.", add_op.error());
+
+ collectionManager.drop_collection("coll1");
+}
+
TEST_F(CollectionSpecificTest, CreateManyCollectionsAndDeleteOneOfThem) {
std::vector<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false),};