diff --git a/internal/proxy/task_index.go b/internal/proxy/task_index.go index 454ffe164e..6bcb5af52b 100644 --- a/internal/proxy/task_index.go +++ b/internal/proxy/task_index.go @@ -239,6 +239,8 @@ func (cit *createIndexTask) parseIndexParams(ctx context.Context) error { return getPrimitiveIndexType(dataType), nil } else if typeutil.IsArrayType(dataType) { return getPrimitiveIndexType(cit.fieldSchema.ElementType), nil + } else if typeutil.IsJSONType(dataType) { + return Params.AutoIndexConfig.ScalarJSONIndexType.GetValue(), nil } return "", fmt.Errorf("create auto index on type:%s is not supported", dataType.String()) }() diff --git a/pkg/util/paramtable/autoindex_param.go b/pkg/util/paramtable/autoindex_param.go index b6499d135c..02a1a90e0a 100644 --- a/pkg/util/paramtable/autoindex_param.go +++ b/pkg/util/paramtable/autoindex_param.go @@ -53,6 +53,7 @@ type AutoIndexConfig struct { ScalarVarcharIndexType ParamItem `refreshable:"true"` ScalarBoolIndexType ParamItem `refreshable:"true"` ScalarFloatIndexType ParamItem `refreshable:"true"` + ScalarJSONIndexType ParamItem `refreshable:"true"` BitmapCardinalityLimit ParamItem `refreshable:"true"` } @@ -166,7 +167,7 @@ func (p *AutoIndexConfig) init(base *BaseTable) { p.ScalarAutoIndexParams = ParamItem{ Key: "scalarAutoIndex.params.build", Version: "2.4.0", - DefaultValue: `{"int": "HYBRID","varchar": "HYBRID","bool": "BITMAP", "float": "INVERTED"}`, + DefaultValue: `{"int": "HYBRID","varchar": "HYBRID","bool": "BITMAP", "float": "INVERTED", "json": "INVERTED"}`, } p.ScalarAutoIndexParams.Init(base.mgr) @@ -207,6 +208,18 @@ func (p *AutoIndexConfig) init(base *BaseTable) { } p.ScalarFloatIndexType.Init(base.mgr) + p.ScalarJSONIndexType = ParamItem{ + Version: "2.5.12", + Formatter: func(v string) string { + m := p.ScalarAutoIndexParams.GetAsJSONMap() + if m == nil { + return "" + } + return m["json"] + }, + } + p.ScalarJSONIndexType.Init(base.mgr) + p.BitmapCardinalityLimit = ParamItem{ Key: "scalarAutoIndex.params.bitmapCardinalityLimit", Version: "2.5.0", diff --git a/tests/go_client/testcases/index_test.go b/tests/go_client/testcases/index_test.go index ee4523af65..5f4cdcaa1a 100644 --- a/tests/go_client/testcases/index_test.go +++ b/tests/go_client/testcases/index_test.go @@ -244,8 +244,11 @@ func TestCreateAutoIndexAllFields(t *testing.T) { for _, field := range schema.Fields { if field.DataType == entity.FieldTypeJSON { idx = index.NewAutoIndex(entity.IP) - _, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(schema.CollectionName, field.Name, idx)) - common.CheckErr(t, err, false, fmt.Sprintf("create auto index on type:%s is not supported", field.DataType)) + opt := client.NewCreateIndexOption(schema.CollectionName, field.Name, idx) + opt.WithExtraParam("json_path", field.Name) + opt.WithExtraParam("json_cast_type", "varchar") + _, err := mc.CreateIndex(ctx, opt) + common.CheckErr(t, err, true) } else { if field.DataType == entity.FieldTypeBinaryVector { idx = index.NewAutoIndex(entity.JACCARD) diff --git a/tests/python_client/testcases/test_index.py b/tests/python_client/testcases/test_index.py index 842dac141f..67582d4252 100644 --- a/tests/python_client/testcases/test_index.py +++ b/tests/python_client/testcases/test_index.py @@ -1184,19 +1184,6 @@ class TestIndexInvalid(TestcaseBase): check_items={"err_code": 1100, "err_msg": "invalid index type: ANNOY"}) - @pytest.mark.tags(CaseLabel.L1) - def test_create_index_json(self): - """ - target: test create index on json fields - method: 1.create collection, and create index - expected: create index raise an error - """ - collection_w = self.init_collection_general(prefix, True, nb=100, is_index=False)[0] - # create index on JSON/Array field is not supported - collection_w.create_index(ct.default_json_field_name, - check_task=CheckTasks.err_res, - check_items={ct.err_code: 1100, - ct.err_msg: "create auto index on type:JSON is not supported"}) @pytest.mark.tags(CaseLabel.L1) def test_create_scalar_index_on_vector_field(self, scalar_index, vector_data_type):