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}}

  1. from pymilvus import utility
  2. utility.has_collection("book")
  1. await milvusClient.collectionManager.hasCollection({
  2. collection_name: "book",
  3. });
  1. hasColl, err := milvusClient.HasCollection(
  2. context.Background(), // ctx
  3. collectionName, // CollectionName
  4. )
  5. if err != nil {
  6. log.Fatal("failed to check whether collection exists:", err.Error())
  7. }
  8. log.Println(hasColl)
  1. R<Boolean> respHasCollection = milvusClient.hasCollection(
  2. HasCollectionParam.newBuilder()
  3. .withCollectionName("book")
  4. .build());
  5. if (respHasCollection.getData() == Boolean.TRUE) {
  6. System.out.println("Collection exists.");
  7. }
  1. 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}}

  1. from pymilvus import Collection
  2. collection = Collection("book") # Get an existing collection.
  3. collection.schema # Return the schema.CollectionSchema of the collection.
  4. collection.description # Return the description of the collection.
  5. collection.name # Return the name of the collection.
  6. collection.is_empty # Return the boolean value that indicates if the collection is empty.
  7. collection.num_entities # Return the number of entities in the collection.
  8. collection.primary_field # Return the schema.FieldSchema of the primary key field.
  9. collection.partitions # Return the list[Partition] object.
  10. collection.indexes # Return the list[Index] object.
  1. await milvusClient.collectionManager.describeCollection({ // Return the name and schema of the collection.
  2. collection_name: "book",
  3. });
  4. await milvusClient.collectionManager.getCollectionStatistics({ // Return the statistics information of the collection.
  5. collection_name: "book",
  6. });
  1. collDesc, err := milvusClient.DescribeCollection( // Return the name and schema of the collection.
  2. context.Background(), // ctx
  3. "book", // CollectionName
  4. )
  5. if err != nil {
  6. log.Fatal("failed to check collection schema:", err.Error())
  7. }
  8. log.Printf("%v\n", collDesc)
  9. collStat, err := milvusClient.GetCollectionStatistics( // Return the statistics information of the collection.
  10. context.Background(), // ctx
  11. "book", // CollectionName
  12. )
  13. if err != nil {
  14. log.Fatal("failed to check collection statistics:", err.Error())
  15. }
  1. R<DescribeCollectionResponse> respDescribeCollection = milvusClient.describeCollection( // Return the name and schema of the collection.
  2. DescribeCollectionParam.newBuilder()
  3. .withCollectionName("book")
  4. .build());
  5. DescCollResponseWrapper wrapperDescribeCollection = new DescCollResponseWrapper(respDescribeCollection.getData());
  6. System.out.println(wrapperDescribeCollection);
  7. R<GetCollectionStatisticsResponse> respCollectionStatistics = milvusClient.getCollectionStatistics( // Return the statistics information of the collection.
  8. GetCollectionStatisticsParam.newBuilder()
  9. .withCollectionName("book")
  10. .build());
  11. GetCollStatResponseWrapper wrapperCollectionStatistics = new GetCollStatResponseWrapper(respCollectionStatistics.getData());
  12. System.out.println("Collection row count: " + wrapperCollectionStatistics.getRowCount());
  1. 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}}

  1. from pymilvus import utility
  2. utility.list_collections()
  1. await milvusClient.collectionManager.showCollections();
  1. listColl, err := milvusClient.ListCollections(
  2. context.Background(), // ctx
  3. )
  4. if err != nil {
  5. log.Fatal("failed to list all collections:", err.Error())
  6. }
  7. log.Println(listColl)
  1. R<ShowCollectionsResponse> respShowCollections = milvusClient.showCollections(
  2. ShowCollectionsParam.newBuilder()
  3. .build());
  4. System.out.println(respShowCollections);
  1. list collections
参数 描述
ctx 控制调用 API 的 Context。

更多内容