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

Null values must not be indexed for auto/string* fields.

Kishore Nallanc1a1d883b070
diff --git a/src/collection.cpp b/src/collection.cpp
index 1fc3c38e..1b09044a 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -2275,7 +2275,7 @@ Option<bool> Collection::check_and_update_schema(nlohmann::json& document, const
if(kv.value().is_null() && new_field.optional) {
// null values are allowed only if field is optional
- kv++;
+ kv = document.erase(kv);
continue;
}
diff --git a/test/collection_all_fields_test.cpp b/test/collection_all_fields_test.cpp
index e84e578b..78575d27 100644
--- a/test/collection_all_fields_test.cpp
+++ b/test/collection_all_fields_test.cpp
@@ -964,6 +964,10 @@ TEST_F(CollectionAllFieldsTest, AutoAndStringStarFieldsShouldAcceptNullValues) {
auto add_op = coll1->add(doc.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
+ auto res = coll1->search("*", {}, "", {}, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();
+ ASSERT_EQ("0", res["hits"][0]["document"]["id"].get<std::string>());
+ ASSERT_EQ(1, res["hits"][0]["document"].size());
+
auto schema = coll1->get_fields();
ASSERT_EQ(4, schema.size());