list_indexes()
Near Deprecation此操作列出指定 Collection 的所有索引。
请求语法
python
list_indexes(
collection_name: str,
using: str = "default",
timeout: float | None,
)
参数:
-
collection_name (str) -
[必需]
现有 Collection 的名称。
如果将其设置为不存在的 Collection,将导致 CollectionNotExistException。
-
index_name (str) -
此操作目标索引的名称。
如果未指定,则使用默认索引。如果该 Collection 有多个索引,则此参数为必填。
如果将其设置为不存在的索引,将导致 IndexNotExistException。
-
using (str) -
所使用连接的别名。
默认值为 default,表示此操作使用默认连接。
-
timeout (float | None)
此操作的超时时长。将其设置为 None 表示当收到任意响应或发生任意错误时,此操作超时。
返回类型:
list
返回值:
以列表形式返回所有已构建索引的名称。
异常:
-
CollectionNotExistException
如果指定的 Collection 不存在,将引发此异常。
示例
python
from pymilvus import (
connections,
Collection,
CollectionSchema,
FieldSchema,
DataType,
utility,
)
# Connect to YOUR_CLUSTER_ENDPOINT
connections.connect()
# Create a collection
collection = Collection(
name="test_collection",
schema=CollectionSchema([
FieldSchema("id", DataType.INT64, is_primary=True),
FieldSchema("vector", DataType.FLOAT_VECTOR, dim=5)
])
)
# Create an index on a scalar field
collection.create_index(
field_name="id"
)
# Set the index parameters
index_params = {
"index_type": "AUTOINDEX",
"metric_type": "COSINE",
"params": {
"nprobe": 10
}
}
# Create an index on the vector field
collection.create_index(
field_name="vector",
index_params=index_params,
timeout=None
)
# List all indexes
utility.list_indexes(
collection_name="test_collection"
) # ['_default_idx_101', '_default_idx_100']
相关操作
以下操作与 list_indexes() 相关