id: check_collection.md
related_key: collection
summary: Learn how to check collection information in Milvus.
查看 Collection 信息
当前主题介绍如何在 Milvus 中查看 collection 信息。
查看 collection 是否存在
验证 Milvus 中是否存在输入的 collection。
{{fragments/multiple_code.md}}
from pymilvus import utility
utility.has_collection("book")
await milvusClient.collectionManager.hasCollection({
collection_name: "book",
});
hasColl, err := milvusClient.HasCollection(
context.Background(), // ctx
collectionName, // CollectionName
)
if err != nil {
log.Fatal("failed to check whether collection exists:", err.Error())
}
log.Println(hasColl)
R<Boolean> respHasCollection = milvusClient.hasCollection(
HasCollectionParam.newBuilder()
.withCollectionName("book")
.build());
if (respHasCollection.getData() == Boolean.TRUE) {
System.out.println("Collection exists.");
}
describe collection -c book
参数 |
描述 |
collection_name |
要查看的 collection 名称。 |
参数 |
描述 |
collection_name |
要查看的 collection 名称。 |
参数 |
描述 |
ctx |
控制调用 API 的 Context。 |
CollectionName |
要查看的 collection 名称。 |
参数 |
描述 |
CollectionName |
要查看的 collection 名称。 |
选项 |
描述 |
-c |
要查看的 collection 名称。 |
查看 collection 详细信息
查看输入 collection 的详细信息
{{fragments/multiple_code.md}}
from pymilvus import Collection
collection = Collection("book") # Get an existing collection.
collection.schema # Return the schema.CollectionSchema of the collection.
collection.description # Return the description of the collection.
collection.name # Return the name of the collection.
collection.is_empty # Return the boolean value that indicates if the collection is empty.
collection.num_entities # Return the number of entities in the collection.
collection.primary_field # Return the schema.FieldSchema of the primary key field.
collection.partitions # Return the list[Partition] object.
collection.indexes # Return the list[Index] object.
await milvusClient.collectionManager.describeCollection({ // Return the name and schema of the collection.
collection_name: "book",
});
await milvusClient.collectionManager.getCollectionStatistics({ // Return the statistics information of the collection.
collection_name: "book",
});
collDesc, err := milvusClient.DescribeCollection( // Return the name and schema of the collection.
context.Background(), // ctx
"book", // CollectionName
)
if err != nil {
log.Fatal("failed to check collection schema:", err.Error())
}
log.Printf("%v\n", collDesc)
collStat, err := milvusClient.GetCollectionStatistics( // Return the statistics information of the collection.
context.Background(), // ctx
"book", // CollectionName
)
if err != nil {
log.Fatal("failed to check collection statistics:", err.Error())
}
R<DescribeCollectionResponse> respDescribeCollection = milvusClient.describeCollection( // Return the name and schema of the collection.
DescribeCollectionParam.newBuilder()
.withCollectionName("book")
.build());
DescCollResponseWrapper wrapperDescribeCollection = new DescCollResponseWrapper(respDescribeCollection.getData());
System.out.println(wrapperDescribeCollection);
R<GetCollectionStatisticsResponse> respCollectionStatistics = milvusClient.getCollectionStatistics( // Return the statistics information of the collection.
GetCollectionStatisticsParam.newBuilder()
.withCollectionName("book")
.build());
GetCollStatResponseWrapper wrapperCollectionStatistics = new GetCollStatResponseWrapper(respCollectionStatistics.getData());
System.out.println("Collection row count: " + wrapperCollectionStatistics.getRowCount());
describe collection -c book
属性 |
返回 |
异常 |
schema |
collection 的 schema 信息。 |
description |
collection 的描述信息。 |
name |
collection 的名称。 |
is_empty |
表示 collection 是否为空的布尔值。 |
num_entities |
collection 中的 entity 数 |
如果 collection 不存在,触发CollectionNotExistException 。 |
primary_field |
collection 的 primary field。 |
partitions |
包含所有 partition 的列表 |
如果 collection 不存在,触发CollectionNotExistException 。 |
indexes |
包含所有索引的列表 |
如果 collection 不存在,触发CollectionNotExistException 。 |
参数 |
说明 |
collection_name |
要查看的 collection 名称。 |
Property |
Description |
status |
{ error_code: number, reason: string } |
schema |
Information of all fields in this collection |
collectionID |
collectionID |
参数 |
描述 |
ctx |
控制调用 API 的 Context。 |
CollectionName |
要查看的 collection 名称。 |
参数 |
说明 |
CollectionName |
要查看的 collection 名称。 |
选项 |
描述 |
-c |
要查看的 collection 名称。 |
列出所有 collection
列出当前 Milvus 实例中的所有 collection。
{{fragments/multiple_code.md}}
from pymilvus import utility
utility.list_collections()
await milvusClient.collectionManager.showCollections();
listColl, err := milvusClient.ListCollections(
context.Background(), // ctx
)
if err != nil {
log.Fatal("failed to list all collections:", err.Error())
}
log.Println(listColl)
R<ShowCollectionsResponse> respShowCollections = milvusClient.showCollections(
ShowCollectionsParam.newBuilder()
.build());
System.out.println(respShowCollections);
list collections
参数 |
描述 |
ctx |
控制调用 API 的 Context。 |
更多内容
- 了解更多 Milvus 的基本操作:
- 探索 Milvus SDK 的 API 参考: