milvus-logo
LFAI
< Docs
  • Java

createIndex()

This operation creates an index for a specific collection.

public void createIndex(CreateIndexReq request)

Request Syntax

createIndex(CreateIndexReq.builder()
    .collectionName(String collectionName)
    .indexParams(List<IndexParam> indexParams)
    .build()
)

BUILDER METHODS:

  • collectionName(String collectionName)

    The name of an existing collection.

  • indexParams(List<IndexParam> indexParams)

    A list of IndexParam objects.

RETURNS:

void

EXCEPTIONS:

  • MilvusClientExceptions

    This exception will be raised when any error occurs during this operation.

Example

// create an index for field "vector"
IndexParam indexParam = IndexParam.builder()
        .metricType(IndexParam.MetricType.L2)
        .indexType(IndexParam.IndexType.AUTOINDEX)
        .fieldName("vector")
        .build();
CreateIndexReq createIndexReq = CreateIndexReq.builder()
        .collectionName("test")
        .indexParams(Collections.singletonList(indexParam))
        .build();
client.createIndex(createIndexReq);