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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Return error when object type is used without enabling nested fields.
Kishore Nallan9277e6f49881
diff --git a/src/field.cpp b/src/field.cppindex bf979c56..1f42243b 100644--- a/src/field.cpp+++ b/src/field.cpp@@ -590,6 +590,13 @@ Option<bool> field::json_field_to_field(bool enable_nested_fields, nlohmann::jsofield_json[fields::infix] = false;}+ if(field_json[fields::type] == field_types::OBJECT || field_json[fields::type] == field_types::OBJECT_ARRAY) {+ if(!enable_nested_fields) {+ return Option<bool>(400, "Type `object` or `object[]` can be used only when nested fields are enabled by "+ "setting` enable_nested_fields` to true.");+ }+ }+auto DEFAULT_VEC_DIST_METRIC = magic_enum::enum_name(vector_distance_type_t::cosine);if(field_json.count(fields::num_dim) == 0) {diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cppindex dfecfb54..c14b4670 100644--- a/test/collection_nested_fields_test.cpp+++ b/test/collection_nested_fields_test.cpp@@ -1920,3 +1920,29 @@ TEST_F(CollectionNestedFieldsTest, HighlightArrayInsideArrayOfObj) {ASSERT_EQ(highlight_meta_doc.dump(), results["hits"][0]["highlight"].dump());}++TEST_F(CollectionNestedFieldsTest, ErrorWhenObjectTypeUsedWithoutEnablingNestedFields) {+ nlohmann::json schema = R"({+ "name": "coll1",+ "fields": [+ {"name": "details", "type": "object", "optional": false }+ ]+ })"_json;++ auto op = collectionManager.create_collection(schema);+ ASSERT_FALSE(op.ok());+ ASSERT_EQ("Type `object` or `object[]` can be used only when nested fields are enabled by setting` "+ "enable_nested_fields` to true.", op.error());++ schema = R"({+ "name": "coll1",+ "fields": [+ {"name": "details", "type": "object[]", "optional": false }+ ]+ })"_json;++ op = collectionManager.create_collection(schema);+ ASSERT_FALSE(op.ok());+ ASSERT_EQ("Type `object` or `object[]` can be used only when nested fields are enabled by setting` "+ "enable_nested_fields` to true.", op.error());+}