FieldSchema
Schema definition for a collection field.
pub struct FieldSchema
PARAMETERS:
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.
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.
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.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.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),
);
let request = CreateCollectionRequest::builder()
.collection_name("books")
.schema(schema)
.build()?;
client.create_collection(request).await?;