FieldSchema
Schema definition for a collection field.
pub struct FieldSchema
PARAMETERS:
field_id: i64ID of the field, assigned by the server.
name: StringName of the field.
description: StringDescription of the field.
data_type: DataTypeData type of the field. See DataType.
element_type: Option<DataType>Element data type of an
Arrayfield. See DataType.is_primary_key: boolWhether the field is the primary key of the collection.
auto_id: boolWhether primary-key values are automatically generated by Milvus.
is_partition_key: boolWhether the field is the partition key of the collection.
is_clustering_key: boolWhether the field is the clustering key of the collection.
nullable: boolWhether the field accepts null values.
element_nullable: boolWhether the field’s elements can be null. Supported for Array sub-fields of a struct array field: it permits individual inner-array values to be null. Struct sub-fields that are themselves arrays use
element_nullablefor the inner values andnullablefor the inner array as a whole.is_dynamic: boolWhether the field is a dynamic (undefined) field.
is_function_output: boolWhether the field is the output of a collection function.
default_value: Option<DefaultValue>Default value used when inserting a row without this field.
type_params: HashMap<String, String>Field-level type parameters, such as
max_length,dimension, ormax_capacity.index_params: HashMap<String, String>Field-level index parameters, such as
index_typeormetric_type.external_field: StringExternal field name used when the field is backed by an external source.
METHODS:
new()- Creates a value initialized with its SDK defaults.name(value)/set_name(value)/get_name()- Sets or returns the field name.description(value)/set_description(value)/get_description()- Sets or returns the description.data_type(value)/set_data_type(value)/get_data_type()- Sets or returns the data type.element_type(value)/set_element_type(value)/get_element_type()- Sets or returns the element type.primary_key(value)/set_primary_key(value)/is_primary_key()- Sets or returns whether the field is the primary key.auto_id(value)/set_auto_id(value)/is_auto_id()- Sets or returns whether primary keys are auto-generated.partition_key(value)/set_partition_key(value)/is_partition_key()- Sets or returns whether the field is the partition key.clustering_key(value)/set_clustering_key(value)/is_clustering_key()- Sets or returns whether the field is the clustering key.nullable(value)/set_nullable(value)/is_nullable()- Sets or returns whether the field accepts null values.element_nullable(value)/set_element_nullable(value)/is_element_nullable()- Sets or returns whether the field’s elements can be null.default_value(value)/set_default_value(value)/get_default_value()- Sets or returns the default value.type_params(value)/set_type_params(value)/get_type_params()- Sets or returns the type params.index_params(value)/set_index_params(value)/get_index_params()- Sets or returns the index params.external_field(value)/set_external_field(value)/get_external_field()- Sets or returns the external field name.get_field_id()- Returns the field ID.is_dynamic()- Returns whether the field is dynamic.is_function_output()- Returns whether the field is a function output.dimension(value)/set_dimension(value)/get_dimension()- Sets or returns the vector dimension.max_length(value)/set_max_length(value)/get_max_length()- Sets or returns the maximum length of aVarCharfield.max_capacity(value)/set_max_capacity(value)/get_max_capacity()- Sets or returns the maximum capacity of anArrayfield.enable_analyzer(value)/set_enable_analyzer(value)/is_analyzer_enabled()- Sets or returns whether the analyzer is enabled.enable_match(value)/set_enable_match(value)/is_match_enabled()- Sets or returns whether BM25 match is enabled.analyzer_params(value)/set_analyzer_params(value)/get_analyzer_params()- Sets or returns the analyzer params.multi_analyzer_params(value)/set_multi_analyzer_params(value)/get_multi_analyzer_params()- Sets or returns the multi-analyzer params.type_param(key, value)- Sets one type param.index_param(key, value)- Sets one index param.
Example
let field = FieldSchema::new()
.name("id")
.data_type(DataType::Int64)
.primary_key(true)
.auto_id(true);
let schema = CollectionSchema::new()
.add_field(field)
.add_field(
FieldSchema::new()
.name("embedding")
.data_type(DataType::FloatVector)
.dimension(4),
)
.add_field(
FieldSchema::new()
.name("tags")
.data_type(DataType::Array)
.element_type(DataType::VarChar)
.max_capacity(8)
.max_length(16)
.nullable(true)
.element_nullable(true),
);
let request = CreateCollectionRequest::builder()
.collection_name("books")
.schema(schema)
.build()?;
client.create_collection(request).await?;