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

Fix flat fields being persisted during update.

Kishore Nalland5968b85f7d0
diff --git a/src/collection.cpp b/src/collection.cpp
index 8ad5e553..241f8684 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -330,6 +330,7 @@ void Collection::batch_index(std::vector<index_record>& index_records, std::vect
if(index_record.indexed.ok()) {
if(index_record.is_update) {
+ remove_flat_fields(index_record.new_doc);
const std::string& serialized_json = index_record.new_doc.dump(-1, ' ', false, nlohmann::detail::error_handler_t::ignore);
bool write_ok = store->insert(get_seq_id_key(index_record.seq_id), serialized_json);
diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp
index e09f57e9..3895f9ad 100644
--- a/test/collection_nested_fields_test.cpp
+++ b/test/collection_nested_fields_test.cpp
@@ -383,6 +383,17 @@ TEST_F(CollectionNestedFieldsTest, SearchOnFieldsOnWildcardSchema) {
ASSERT_EQ(highlight_doc.dump(), results["hits"][0]["highlight"]["snippet"].dump());
ASSERT_EQ(0, results["hits"][0]["highlights"].size());
+ // after update also the flat fields or meta should not be present on disk
+ doc["employees"]["tags"][0] = "senior plumber 2";
+ auto update_op = coll1->add(doc.dump(), UPSERT);
+ ASSERT_TRUE(add_op.ok());
+
+ raw_doc.clear();
+ coll1->get_document_from_store(0, raw_doc, true);
+ ASSERT_EQ(0, raw_doc.count(".flat"));
+ ASSERT_EQ(0, raw_doc.count("employees.tags"));
+ ASSERT_EQ(4, raw_doc.size());
+
// search specific nested fields, only matching field is highlighted by default
results = coll1->search("one shoe", {"locations.address.street", "employees.tags"}, "", {}, sort_fields,
{0}, 10, 1, FREQUENCY, {true}).get();