Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/cn/docs/changelog/hugegraph-0.2-release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ weight: 23
- 图数据接口
- Gremlin接口

更多细节详见[API文档](/clients/hugegraph-api.html)
更多细节详见[API文档](/docs/clients/restful-api)

### 后端支持

Expand Down
2 changes: 1 addition & 1 deletion content/cn/docs/clients/gremlin-console.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
# ......
```

将 `channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer` 修改成 `channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer` 或直接注释,然后按照[步骤](/docs/quickstart/hugegraph-server/)启动 HugeGraph-Server。
将 `channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer` 修改成 `channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer` 或直接注释,然后按照[步骤](/cn/docs/quickstart/hugegraph/hugegraph-server/)启动 HugeGraph-Server。

下面进入 Gremlin-Console:

Expand Down
79 changes: 40 additions & 39 deletions content/cn/docs/clients/hugegraph-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ weight: 2

本文的代码都是`java`语言写的,但其风格与`gremlin(groovy)`是非常类似的。用户只需要把代码中的变量声明替换成`def`或直接去掉,
就能将`java`代码转变为`groovy`;另外就是每一行语句最后可以不加分号,`groovy`认为一行就是一条语句。
用户在`HugeGraph-Studio`中编写的`gremlin(groovy)`可以参考本文的`java`代码,下面会举出几个例子。

用户在`HugeGraph-Hubble`中编写的`gremlin(groovy)`可以参考本文的`java`代码,下面会举出几个例子。

### 1 HugeGraph-Client

Expand All @@ -15,31 +16,31 @@ HugeGraph-Client 是操作 graph 的总入口,用户必须先创建出 HugeGra
目前 HugeGraph-Client 只允许连接服务端已存在的图,无法自定义图进行创建。其创建方法如下:

```java
// HugeGraphServer地址:"http://localhost:8080"
// HugeGraphServer 地址:"http://localhost:8080"
// 图的名称:"hugegraph"
HugeClient hugeClient = HugeClient.builder("http://localhost:8080", "hugegraph")
.configTimeout(20) // 默认 20s 超时
.configUser("**", "**") // 默认未开启用户权限
.build();
```

上述创建 HugeClient 的过程如果失败会抛出异常,用户需要try-catch。如果成功则继续获取 schema、graph 以及 gremlin 的 manager。
上述创建 HugeClient 的过程如果失败会抛出异常,用户需要 try-catch。如果成功则继续获取 schema、graph 以及 gremlin 的 manager。

在`HugeGraph - Hubble / Studio`中通过`gremlin`来操作时,不需要使用`HugeClient`,可以忽略。
在`HugeGraph - Hubble`中通过`gremlin`来操作时,不需要使用`HugeClient`,可以忽略。

### 2 元数据

#### 2.1 SchemaManager

SchemaManager 用于管理 HugeGraph 中的四种元数据,分别是PropertyKey(属性类型)、VertexLabel(顶点类型)、EdgeLabel(边类型)和 IndexLabel(索引标签)。在定义元数据信息之前必须先创建 SchemaManager 对象。
SchemaManager 用于管理 HugeGraph 中的四种元数据,分别是 PropertyKey(属性类型)、VertexLabel(顶点类型)、EdgeLabel(边类型)和 IndexLabel(索引标签)。在定义元数据信息之前必须先创建 SchemaManager 对象。

用户可使用如下方法获得SchemaManager对象
用户可使用如下方法获得 SchemaManager 对象

```java
SchemaManager schema = hugeClient.schema()
```

在`HugeGraph-Studio`中通过`gremlin`创建`schema`对象:
在`HugeGraph-Hubble`中通过`gremlin`创建`schema`对象:

```groovy
schema = graph.schema()
Expand Down Expand Up @@ -96,7 +97,7 @@ PropertyKey 允许定义的约束信息包括:name、datatype、cardinality、
schema.propertyKey("name").asText().valueSet().ifNotExist().create()
```

在`HugeGraph-Studio`中通过`gremlin`创建上述`PropertyKey`对象的语法完全一致,如果用户没有定义出`schema`变量,应该这样写:
在`HugeGraph-Hubble`中通过`gremlin`创建上述`PropertyKey`对象的语法完全一致,如果用户没有定义出`schema`变量,应该这样写:

```groovy
graph.schema().propertyKey("name").asText().valueSet().ifNotExist().create()
Expand All @@ -115,10 +116,10 @@ schema.propertyKey("name").remove()
##### 2.2.4 查询 PropertyKey

```java
// 获取PropertyKey对象
// 获取 PropertyKey 对象
schema.getPropertyKey("name")

// 获取PropertyKey属性
// 获取 PropertyKey 属性
schema.getPropertyKey("name").cardinality()
schema.getPropertyKey("name").dataType()
schema.getPropertyKey("name").name()
Expand All @@ -131,15 +132,15 @@ schema.getPropertyKey("name").userdata()

VertexLabel 用来定义顶点类型,描述顶点的约束信息:

VertexLabel 允许定义的约束信息包括:name、idStrategy、properties、primaryKeys和 nullableKeys,下面逐一介绍。
VertexLabel 允许定义的约束信息包括:name、idStrategy、properties、primaryKeys 和 nullableKeys,下面逐一介绍。

- name: 属性的名字,用来区分不同的 VertexLabel,不允许有同名的属性;

| interface | param | must set |
|--------------------------|-------|----------|
| vertexLabel(String name) | name | y |

- idStrategy: 每一个 VertexLabel 都可以选择自己的 Id 策略,目前有三种策略供选择,即 Automatic(自动生成)、Customize(用户传入)和 PrimaryKey(主属性键)。其中 Automatic 使用 Snowflake 算法生成 Id,Customize 需要用户自行传入字符串或数字类型的 Id,PrimaryKey 则允许用户从 VertexLabel 的属性中选择若干主属性作为区分的依据,HugeGraph 内部会根据主属性的值拼接生成 Id。idStrategy 默认使用 Automatic的,但如果用户没有显式设置 idStrategy 又调用了 primaryKeys(...) 方法设置了主属性,则 idStrategy 将自动使用 PrimaryKey;
- idStrategy: 每一个 VertexLabel 都可以选择自己的 Id 策略,目前有三种策略供选择,即 Automatic(自动生成)、Customize(用户传入)和 PrimaryKey(主属性键)。其中 Automatic 使用 Snowflake 算法生成 Id,Customize 需要用户自行传入字符串或数字类型的 Id,PrimaryKey 则允许用户从 VertexLabel 的属性中选择若干主属性作为区分的依据,HugeGraph 内部会根据主属性的值拼接生成 Id。idStrategy 默认使用 Automatic 的,但如果用户没有显式设置 idStrategy 又调用了 primaryKeys(...) 方法设置了主属性,则 idStrategy 将自动使用 PrimaryKey;

| interface | idStrategy | description |
|----------------------|------------------|---------------------------------------------------------|
Expand Down Expand Up @@ -176,7 +177,7 @@ VertexLabel 允许定义的约束信息包括:name、idStrategy、properties

注意:primaryKeys 和 nullableKeys 不能有交集,因为一个属性不能既作为主属性,又是可空的。

- enableLabelIndex:用户可以指定是否需要为label创建索引。不创建则无法全局搜索指定label的顶点和边,创建则可以全局搜索,做类似于`g.V().hasLabel('person'), g.E().has('label', 'person')`这样的查询,
- enableLabelIndex:用户可以指定是否需要为 label 创建索引。不创建则无法全局搜索指定 label 的顶点和边,创建则可以全局搜索,做类似于`g.V().hasLabel('person'), g.E().has('label', 'person')`这样的查询,
但是插入数据时性能上会更加慢,并且需要占用更多的存储空间。此项默认为 true。

| interface | description |
Expand Down Expand Up @@ -223,10 +224,10 @@ schema.vertexLabel("person").remove();
##### 2.3.5 查询 VertexLabel

```java
// 获取VertexLabel对象
// 获取 VertexLabel 对象
schema.getVertexLabel("name")

// 获取property key属性
// 获取 property key 属性
schema.getVertexLabel("person").idStrategy()
schema.getVertexLabel("person").primaryKeys()
schema.getVertexLabel("person").name()
Expand Down Expand Up @@ -258,7 +259,7 @@ EdgeLabel 允许定义的约束信息包括:name、sourceLabel、targetLabel
| sourceLabel(String label) | label | y |
| targetLabel(String label) | label | y |

- frequency: 字面意思是频率,表示在两个具体的顶点间某个关系出现的次数,可以是单次(single)或多次(frequency),默认为single
- frequency: 字面意思是频率,表示在两个具体的顶点间某个关系出现的次数,可以是单次(single)或多次(frequency),默认为 single

| interface | frequency | description |
|--------------|-----------|-------------------------------------|
Expand All @@ -279,7 +280,7 @@ EdgeLabel 允许定义的约束信息包括:name、sourceLabel、targetLabel

- nullableKeys: 与顶点中的 nullableKeys 概念一致,不再赘述

注意:sortKeys 和 nullableKeys也不能有交集
注意:sortKeys 和 nullableKeys 也不能有交集

- enableLabelIndex:与顶点中的 enableLabelIndex 概念一致,不再赘述

Expand Down Expand Up @@ -311,10 +312,10 @@ schema.edgeLabel("knows").remove();
##### 2.4.5 查询 EdgeLabel

```java
// 获取EdgeLabel对象
// 获取 EdgeLabel 对象
schema.getEdgeLabel("knows")

// 获取property key属性
// 获取 property key 属性
schema.getEdgeLabel("knows").frequency()
schema.getEdgeLabel("knows").sourceLabel()
schema.getEdgeLabel("knows").targetLabel()
Expand Down Expand Up @@ -356,28 +357,28 @@ IndexLabel 允许定义的约束信息包括:name、baseType、baseValue、ind

- indexType: 建立的索引类型,目前支持五种,即 Secondary、Range、Search、Shard 和 Unique。
- Secondary 支持精确匹配的二级索引,允许建立联合索引,联合索引支持索引前缀搜索
- 单个属性,支持相等查询,比如:person顶点的city属性的二级索引,可以用`g.V().has("city", "北京")
`查询"city属性值是北京"的全部顶点
- 联合索引,支持前缀查询和相等查询,比如:person顶点的city和street属性的联合索引,可以用`g.V().has
- 单个属性,支持相等查询,比如:person 顶点的 city 属性的二级索引,可以用`g.V().has("city", "北京")
`查询"city 属性值是北京"的全部顶点
- 联合索引,支持前缀查询和相等查询,比如:person 顶点的 city 和 street 属性的联合索引,可以用`g.V().has
("city", "北京").has('street', '中关村街道')
`查询"city属性值是北京且street属性值是中关村"的全部顶点,或者`g.V()
.has("city", "北京")`查询"city属性值是北京"的全部顶点
> secondary index的查询都是基于"是"或者"相等"的查询条件,不支持"部分匹配"
.has("city", "北京")`查询"city 属性值是北京"的全部顶点
> secondary index 的查询都是基于"是"或者"相等"的查询条件,不支持"部分匹配"
- Range 支持数值类型的范围查询
- 必须是单个数字或者日期属性,比如:person顶点的age属性的范围索引,可以用`g.V().has("age", P.gt(18))
- 必须是单个数字或者日期属性,比如:person 顶点的 age 属性的范围索引,可以用`g.V().has("age", P.gt(18))
`查询"age属性值大于18"的顶点。除了`P.gt()`以外,还支持`P.gte()`, `P.lte()`, `P.lt()`,
`P.eq()`, `P.between()`, `P.inside()`和`P.outside()`等
- Search 支持全文检索的索引
- 必须是单个文本属性,比如:person顶点的address属性的全文索引,可以用`g.V().has("address", Text
.contains('大厦')`查询"address属性中包含大厦"的全部顶点
> search index的查询是基于"是"或者"包含"的查询条件
- 必须是单个文本属性,比如:person 顶点的 address 属性的全文索引,可以用`g.V().has("address", Text
.contains('大厦')`查询"address 属性中包含大厦"的全部顶点
> search index 的查询是基于"是"或者"包含"的查询条件
- Shard 支持前缀匹配 + 数字范围查询的索引
- N个属性的分片索引,支持前缀相等情况下的范围查询,比如:person顶点的city和age属性的分片索引,可以用`g.V().has
- N 个属性的分片索引,支持前缀相等情况下的范围查询,比如:person 顶点的 city 和 age 属性的分片索引,可以用`g.V().has
("city", "北京").has("age", P.between(18, 30))
`查询"city属性是北京且年龄大于等于18小于30"的全部顶点
- shard index N个属性全是文本属性时,等价于secondary index
- shard index只有单个数字或者日期属性时,等价于range index
> shard index可以有任意数字或者日期属性,但是查询时最多只能提供一个范围查找条件,且该范围查找条件的属性的前缀属性都是相等查询条件
`查询"city 属性是北京且年龄大于等于 18 小于 30"的全部顶点
- shard index N 个属性全是文本属性时,等价于 secondary index
- shard index 只有单个数字或者日期属性时,等价于 range index
> shard index 可以有任意数字或者日期属性,但是查询时最多只能提供一个范围查找条件,且该范围查找条件的属性的前缀属性都是相等查询条件
- Unique 支持属性值唯一性约束,即可以限定属性的值不重复,允许联合索引,但不支持查询
- 单个或者多个属性的唯一性索引,不可用来查询,只可对属性的值进行限定,当出现重复值时将报错

Expand Down Expand Up @@ -408,10 +409,10 @@ schema.indexLabel("personByAge").remove()
##### 2.5.4 查询 IndexLabel

```java
// 获取IndexLabel对象
// 获取 IndexLabel 对象
schema.getIndexLabel("personByAge")

// 获取property key属性
// 获取 property key 属性
schema.getIndexLabel("personByAge").baseType()
schema.getIndexLabel("personByAge").baseValue()
schema.getIndexLabel("personByAge").indexFields()
Expand All @@ -431,7 +432,7 @@ Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java",
```

- 添加顶点的关键是顶点属性,添加顶点函数的参数个数必须为偶数,且满足`key1 -> val1, key2 -> val2 ···`的顺序排列,键值对之间的顺序是自由的。
- 参数中必须包含一对特殊的键值对,就是`T.label -> "val"`,用来定义该顶点的类别,以便于程序从缓存或后端获取到该VertexLabel的schema定义,然后做后续的约束检查。例子中的label定义为person
- 参数中必须包含一对特殊的键值对,就是`T.label -> "val"`,用来定义该顶点的类别,以便于程序从缓存或后端获取到该 VertexLabel 的 schema 定义,然后做后续的约束检查。例子中的 label 定义为 person
- 如果顶点类型的 Id 策略为 `AUTOMATIC`,则不允许用户传入 id 键值对。
- 如果顶点类型的 Id 策略为 `CUSTOMIZE_STRING`,则用户需要自己传入 String 类型 id 的值,键值对形如:`"T.id", "123456"`。
- 如果顶点类型的 Id 策略为 `CUSTOMIZE_NUMBER`,则用户需要自己传入 Number 类型 id 的值,键值对形如:`"T.id", 123456`。
Expand All @@ -448,12 +449,12 @@ Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java",
Edge knows1 = marko.addEdge("knows", vadas, "city", "Beijing");
```

- 由(源)顶点来调用添加边的函数,函数第一个参数为边的label,第二个参数是目标顶点,这两个参数的位置和顺序是固定的。后续的参数就是`key1 -> val1, key2 -> val2 ···`的顺序排列,设置边的属性,键值对顺序自由。
- 由(源)顶点来调用添加边的函数,函数第一个参数为边的 label,第二个参数是目标顶点,这两个参数的位置和顺序是固定的。后续的参数就是`key1 -> val1, key2 -> val2 ···`的顺序排列,设置边的属性,键值对顺序自由。
- 源顶点和目标顶点必须符合 EdgeLabel 中 source-label 和 target-label 的定义,不能随意添加。
- 对于非 nullableKeys 的属性,必须要赋值。

**注意:当frequency为multiple时必须要设置sortKeys对应属性类型的值。**
**注意:当 frequency 为 multiple 时必须要设置 sortKeys 对应属性类型的值。**

### 4 简单示例

简单示例见[HugeGraph-Client](/docs/quickstart/hugegraph-client)
简单示例见[HugeGraph-Client](/cn/docs/quickstart/client/hugegraph-client)
2 changes: 1 addition & 1 deletion content/cn/docs/clients/restful-api/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ weight: 1
HugeGraph-Server通过HugeGraph-API基于HTTP协议为Client提供操作图的接口,主要包括元数据和
图数据的增删改查,遍历算法,变量,图操作及其他操作。

除了下方的文档,你还可以通过 `localhost:8080/swagger-ui/index.html` 访问 `swagger-ui` 以查看 `RESTful API`。[示例可以参考此处](/cn/docs/quickstart/hugegraph-server#swaggerui-example)
除了下方的文档,你还可以通过 `localhost:8080/swagger-ui/index.html` 访问 `swagger-ui` 以查看 `RESTful API`。[示例可以参考此处](/cn/docs/quickstart/hugegraph/hugegraph-server#swaggerui-example)

[comment]: <> (- Graph Schema)

Expand Down
2 changes: 1 addition & 1 deletion content/cn/docs/clients/restful-api/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ DELETE http://localhost:8080/graphs/hugegraph/tasks/2

#### 7.1.4 取消某个异步任务,**该异步任务必须具有处理中断的能力**

假设已经通过[Gremlin API](../gremlin)创建了一个异步任务如下:
假设已经通过[Gremlin API](/cn/docs/clients/restful-api/gremlin)创建了一个异步任务如下:

```groovy
"for (int i = 0; i < 10; i++) {" +
Expand Down
Loading