更新时间:2024-04-17 GMT+08:00

添加索引

您可以使用GES提供的接口添加索引。示例代码如下:

public static void excuteCreateIndex(GraphClient graphClient) throws ApiExcepti
  {
      CreateIndexReq req = new CreateIndexReq();
      //表示是否有label,不区分大小写,不填时默认为false
      req.setHasLabel("true"); 
      //索引名称,只能包含字母或数字不能包含特殊字符,无默认值
      req.setIndexName("ageIndex");
      //元素类型,可选值有“vertex“或”edge“,不区分大小写,无默认值
      req.setElementType("vertex");
      //索引类型,可选”GlobalCompositeVertexIndex”或”GlobalCompositeEdgeIndex”,区分大小写,无默认值
      // indexType应与elementType一一对应,如elementType为vertex时,indexType应为GlobalCompositeVertexIndex;elementType为edge时,indexType应为GlobalCompositeEdgeIndex,否则会创建索引失败
      req.setIndexType("GlobalCompositeVertexIndex");
      //索引的属性列表 (支持的属性类型有:int, float, double, long, enum, char array, string, date)
      //若hasLabel为false或null,则该项为必选
      req.setIndexProperty(req.setIndexProperty(new String[] {"age"});)
      Map<String, Object> result = graphClient.createIndex(req);
      System.out.print(MapUtils.map2json(result));
  }