enhance: support auto index type for json index (#42071)

issue: https://github.com/milvus-io/milvus/issues/42070

---------

Signed-off-by: sunby <sunbingyi1992@gmail.com>
This commit is contained in:
Bingyi Sun 2025-06-09 21:22:34 +08:00 committed by GitHub
parent 317e7999da
commit ffb2877992
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 16 deletions

View File

@ -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())
}()

View File

@ -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",

View File

@ -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)

View File

@ -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):