Browse Source

Set index name (#286)

Signed-off-by: groot <yihua.mo@zilliz.com>
groot 3 years ago
parent
commit
7d9037a93a

+ 3 - 1
src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java

@@ -994,7 +994,9 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
             }
 
             CreateIndexRequest createIndexRequest = createIndexRequestBuilder.setCollectionName(requestParam.getCollectionName())
-                    .setFieldName(requestParam.getFieldName()).build();
+                    .setFieldName(requestParam.getFieldName())
+                    .setIndexName(requestParam.getIndexName())
+                    .build();
 
             Status response = blockingStub().createIndex(createIndexRequest);
 

+ 1 - 0
src/main/java/io/milvus/param/Constant.java

@@ -36,6 +36,7 @@ public class Constant {
     public static final String BUCKET = "bucket";
     public static final String FAILED_REASON = "failed_reason";
     public static final String IMPORT_FILES = "files";
+    public static final String DEFAULT_INDEX_NAME = "_default_idx";
 
     // max value for waiting loading collection/partition interval, unit: millisecond
     public static final Long MAX_WAITING_LOADING_INTERVAL = 2000L;

+ 20 - 0
src/main/java/io/milvus/param/index/CreateIndexParam.java

@@ -26,6 +26,7 @@ import io.milvus.param.MetricType;
 import io.milvus.param.ParamUtils;
 import lombok.Getter;
 import lombok.NonNull;
+import org.apache.commons.lang3.StringUtils;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -37,6 +38,7 @@ import java.util.Map;
 public class CreateIndexParam {
     private final String collectionName;
     private final String fieldName;
+    private final String indexName;
     private final Map<String, String> extraParam = new HashMap<>();
     private final boolean syncMode;
     private final long syncWaitingInterval;
@@ -45,6 +47,7 @@ public class CreateIndexParam {
     private CreateIndexParam(@NonNull Builder builder) {
         this.collectionName = builder.collectionName;
         this.fieldName = builder.fieldName;
+        this.indexName = builder.indexName;
         this.extraParam.put(Constant.INDEX_TYPE, builder.indexType.name());
         this.extraParam.put(Constant.METRIC_TYPE, builder.metricType.name());
         this.extraParam.put(Constant.PARAMS, builder.extraParam);
@@ -64,6 +67,7 @@ public class CreateIndexParam {
         private String collectionName;
         private String fieldName;
         private IndexType indexType;
+        private String indexName;
         private MetricType metricType;
         private String extraParam;
 
@@ -117,6 +121,18 @@ public class CreateIndexParam {
             return this;
         }
 
+        /**
+         * The name of index which will be created. Then you can use the index name to check the state of index.
+         * If no index name is specified, the default index name("_default_idx") is used.
+         *
+         * @param indexName index name
+         * @return <code>Builder</code>
+         */
+        public Builder withIndexName(@NonNull String indexName) {
+            this.indexName = indexName;
+            return this;
+        }
+
         /**
          * Sets the metric type.
          *
@@ -191,6 +207,10 @@ public class CreateIndexParam {
             ParamUtils.CheckNullEmptyString(collectionName, "Collection name");
             ParamUtils.CheckNullEmptyString(fieldName, "Field name");
 
+            if (indexName == null || StringUtils.isBlank(indexName)) {
+                indexName = Constant.DEFAULT_INDEX_NAME;
+            }
+
             if (indexType == IndexType.INVALID) {
                 throw new ParamException("Index type is required");
             }