This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-doc.git
The following commit(s) were added to refs/heads/master by this push:
new a72b7ece chore: improve docs for gremlin console (#354)
a72b7ece is described below
commit a72b7ece67c2e53023ceb64ac4f26baf7b61cbbb
Author: V_Galaxy <[email protected]>
AuthorDate: Mon Apr 15 16:18:16 2024 +0800
chore: improve docs for gremlin console (#354)
* improve
* sync EN doc
---
content/cn/docs/clients/gremlin-console.md | 86 ++++++------------------------
content/en/docs/clients/gremlin-console.md | 82 ++++++----------------------
2 files changed, 32 insertions(+), 136 deletions(-)
diff --git a/content/cn/docs/clients/gremlin-console.md
b/content/cn/docs/clients/gremlin-console.md
index 4a9992e0..bf4ebd69 100644
--- a/content/cn/docs/clients/gremlin-console.md
+++ b/content/cn/docs/clients/gremlin-console.md
@@ -9,74 +9,20 @@ Gremlin-Console 是由 Tinkerpop 自己开发的一个交互式客户端,用
- 单机离线调用模式
- Client/Server 请求模式
-### 1 单机离线调用模式
+**注:Gremlin-Console 只是便于用户快速上手体验,不建议在生产环境中使用。**
-由于 lib 目录下已经包含了 HugeCore 的 jar 包,且 HugeGraph 已经作为插件注册到 Console 中,用户可以直接写
groovy 脚本调用 HugeGraph-Core 的代码,然后交由 Gremlin-Console 内的解析引擎执行,就能在不启动 Server
的情况下操作图。
+### 1 单机离线调用模式
-这种模式便于用户快速上手体验,但是不适合大量数据插入和查询的场景。下面给一个示例:
+由于 lib 目录下已经包含了 HugeCore 的 jar 包,且 HugeGraph-Server 已经作为插件注册到 Gremlin-Console
中,用户可以直接写 Groovy 脚本调用 HugeGraph-Core 的代码,然后交由 Gremlin-Console
内的解析引擎执行,就能在**不启动** Server 的情况下操作图。
-在 script 目录下有一个示例脚本 `example.groovy`:
+这里提供一个示例,首先修改 `hugegraph.properties` 配置使用 Memory 后端 (使用其他后端可能会出现一些初始化问题):
-```groovy
-import org.apache.hugegraph.HugeFactory
-import org.apache.hugegraph.backend.id.IdGenerator
-import org.apache.hugegraph.dist.RegisterUtil
-import org.apache.hugegraph.type.define.NodeRole
-import org.apache.tinkerpop.gremlin.structure.T
-
-RegisterUtil.registerRocksDB()
-
-conf = "conf/graphs/hugegraph.properties"
-graph = HugeFactory.open(conf)
-graph.serverStarted(IdGenerator.of("server-tinkerpop"), NodeRole.MASTER)
-schema = graph.schema()
-
-schema.propertyKey("name").asText().ifNotExist().create()
-schema.propertyKey("age").asInt().ifNotExist().create()
-schema.propertyKey("city").asText().ifNotExist().create()
-schema.propertyKey("weight").asDouble().ifNotExist().create()
-schema.propertyKey("lang").asText().ifNotExist().create()
-schema.propertyKey("date").asText().ifNotExist().create()
-schema.propertyKey("price").asInt().ifNotExist().create()
-
-schema.vertexLabel("person").properties("name", "age",
"city").primaryKeys("name").ifNotExist().create()
-schema.vertexLabel("software").properties("name", "lang",
"price").primaryKeys("name").ifNotExist().create()
-schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create()
-schema.indexLabel("personByAgeAndCity").onV("person").by("age",
"city").secondary().ifNotExist().create()
-schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create()
-schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date",
"weight").ifNotExist().create()
-schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date",
"weight").ifNotExist().create()
-schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create()
-schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create()
-schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create()
-
-marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city",
"Beijing")
-vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city",
"Hongkong")
-lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java",
"price", 328)
-josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city",
"Beijing")
-ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang",
"java", "price", 199)
-peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city",
"Shanghai")
-
-marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5)
-marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0)
-marko.addEdge("created", lop, "date", "20171210", "weight", 0.4)
-josh.addEdge("created", lop, "date", "20091111", "weight", 0.4)
-josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0)
-peter.addEdge("created", lop, "date", "20170324", "weight", 0.2)
-
-graph.tx().commit()
-
-g = graph.traversal()
-
-System.out.println(">>>> query all vertices: size=" + g.V().toList().size())
-System.out.println(">>>> query all edges: size=" + g.E().toList().size())
+```properties
+backend=memory
+serializer=text
```
-其实这一段 groovy 脚本几乎就是 Java 代码,不同之处仅在于变量的定义可以不写类型声明,以及每一行末尾的分号可以去掉。
-
-> `g.V()` 是获取所有的顶点,`g.E()` 是获取所有的边,`toList()` 是把结果存到一个 List 中,参考 [TinkerPop
Terminal
Steps](http://tinkerpop.apache.org/docs/current/reference/#terminal-steps)。
-
-下面进入 gremlin-console,并传入该脚本令其执行:
+然后输入下述命令:
```bash
> ./bin/gremlin-console.sh -- -i scripts/example.groovy
@@ -97,7 +43,9 @@ gremlin>
> 这里的 `--` 会被 getopts 解析为最后一个 option,这样后面的 options 就可以传入 Gremlin-Console
> 进行处理了。`-i` 代表 `Execute the specified script and leave the console open on
> completion`,更多的选项可以参考 Gremlin-Console
> 的[源代码](https://github.com/apache/tinkerpop/blob/3.5.1/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy#L483)。
-可以看到,插入了 6 个顶点、6 条边,并查询出来了。进入 console 之后,还可继续输入 groovy 语句对图做操作:
+其中
[`example.groovy`](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-dist/src/assembly/static/scripts/example.groovy)
是 scripts 目录下的一个示例脚本,该脚本插入了一些数据,并在最后查询图中顶点和边的数量。
+
+此时还可以继续输入 Gremlin 语句对图进行操作:
```groovy
gremlin> g.V()
@@ -123,7 +71,7 @@ gremlin>
因为 Gremlin-Console 只能通过 WebSocket 连接 HugeGraph-Server,默认 HugeGraph-Server
是对外提供 HTTP 连接的,所以先修改 gremlin-server 的配置。
-*注意:将连接方式修改为 WebSocket 后,HugeGraph-Client、HugeGraph-Loader、HugeGraph-Hubble
等配套工具都不能使用了。*
+**注意:将连接方式修改为 WebSocket 后,HugeGraph-Client、HugeGraph-Loader、HugeGraph-Hubble
等配套工具都不能使用了。**
```yaml
# vim conf/gremlin-server.yaml
@@ -134,9 +82,9 @@ 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/)启动 HugegraphServer。
+将 `channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer`
修改成 `channelizer:
org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer`
或直接注释,然后按照[步骤](/docs/quickstart/hugegraph-server/)启动 HugeGraph-Server。
-下面进入 gremlin-console:
+下面进入 Gremlin-Console:
```bash
> ./bin/gremlin-console.sh
@@ -150,7 +98,7 @@ plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
```
-连接 server,需在配置文件中指定连接参数,在 conf 目录下有一个默认的 `remote.yaml`:
+连接 Server,需在配置文件中指定连接参数,在 conf 目录下有一个默认的 `remote.yaml`:
```yaml
# cat conf/remote.yaml
@@ -170,7 +118,7 @@ gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
```
-连接成功之后,如果在启动 HugeGraphServer 的过程中导入了示例图 `example.groovy`,就可以在 console 中直接进行查询
+连接成功之后,如果在启动 HugeGraph-Server 的过程中导入了示例图,就可以在 Gremlin-Console 中直接进行查询:
```groovy
gremlin> :> hugegraph.traversal().V()
@@ -202,4 +150,4 @@ gremlin> :> @script
gremlin>
```
-更多关于 gremlin-console 的使用,请参考 [Tinkerpop
官网](http://tinkerpop.apache.org/docs/current/reference/)
+更多关于 Gremlin-Console 的使用,请参考 [Tinkerpop
官网](http://tinkerpop.apache.org/docs/current/reference/)。
diff --git a/content/en/docs/clients/gremlin-console.md
b/content/en/docs/clients/gremlin-console.md
index f44f3e7e..4bc49f48 100644
--- a/content/en/docs/clients/gremlin-console.md
+++ b/content/en/docs/clients/gremlin-console.md
@@ -9,74 +9,20 @@ Gremlin-Console is an interactive client developed by
TinkerPop. Users can use t
- Stand-alone offline mode
- Client/Server mode
-### 1 Stand-alone offline mode
+**Note: Gremlin-Console is only for users to quickly get started and
experience, it is not recommended for use in production environments.**
-Since the lib directory already contains the HugeCore jar package, and
HugeGraph has been registered in the Console as a plug-in, the users can write
a groovy script directly to call the code of HugeGraph-Core, and then hand it
over to the parsing engine in Gremlin-Console for execution. As a result, the
users can operate the graph without starting the Server.
+### 1 Stand-alone offline mode
-This mode is convenient for users to get started quickly, but it is not
suitable for scenarios where a large amount of data is inserted and queried.
Here is an example:
+Since the lib directory already contains the HugeCore jar package, and
HugeGraph-Server has been registered in the Console as a plug-in, the users can
write a groovy script directly to call the code of HugeGraph-Core, and then
hand it over to the parsing engine in Gremlin-Console for execution. As a
result, the users can operate the graph **without** starting the Server.
-There is a sample script in the script directory `example.groovy`:
+Here is an example, first modify the `hugegraph.properties` configuration to
use the Memory backend (using other backends may encounter some initialization
issues):
-```groovy
-import org.apache.hugegraph.HugeFactory
-import org.apache.hugegraph.backend.id.IdGenerator
-import org.apache.hugegraph.dist.RegisterUtil
-import org.apache.hugegraph.type.define.NodeRole
-import org.apache.tinkerpop.gremlin.structure.T
-
-RegisterUtil.registerRocksDB()
-
-conf = "conf/graphs/hugegraph.properties"
-graph = HugeFactory.open(conf)
-graph.serverStarted(IdGenerator.of("server-tinkerpop"), NodeRole.MASTER)
-schema = graph.schema()
-
-schema.propertyKey("name").asText().ifNotExist().create()
-schema.propertyKey("age").asInt().ifNotExist().create()
-schema.propertyKey("city").asText().ifNotExist().create()
-schema.propertyKey("weight").asDouble().ifNotExist().create()
-schema.propertyKey("lang").asText().ifNotExist().create()
-schema.propertyKey("date").asText().ifNotExist().create()
-schema.propertyKey("price").asInt().ifNotExist().create()
-
-schema.vertexLabel("person").properties("name", "age",
"city").primaryKeys("name").ifNotExist().create()
-schema.vertexLabel("software").properties("name", "lang",
"price").primaryKeys("name").ifNotExist().create()
-schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create()
-schema.indexLabel("personByAgeAndCity").onV("person").by("age",
"city").secondary().ifNotExist().create()
-schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create()
-schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date",
"weight").ifNotExist().create()
-schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date",
"weight").ifNotExist().create()
-schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create()
-schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create()
-schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create()
-
-marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city",
"Beijing")
-vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city",
"Hongkong")
-lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java",
"price", 328)
-josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city",
"Beijing")
-ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang",
"java", "price", 199)
-peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city",
"Shanghai")
-
-marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5)
-marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0)
-marko.addEdge("created", lop, "date", "20171210", "weight", 0.4)
-josh.addEdge("created", lop, "date", "20091111", "weight", 0.4)
-josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0)
-peter.addEdge("created", lop, "date", "20170324", "weight", 0.2)
-
-graph.tx().commit()
-
-g = graph.traversal()
-
-System.out.println(">>>> query all vertices: size=" + g.V().toList().size())
-System.out.println(">>>> query all edges: size=" + g.E().toList().size())
+```properties
+backend=memory
+serializer=text
```
-In fact, this groovy script is almost Java code, the only difference is that
the variable definition can be written without the type declaration, and the
semicolon at the end of each line can be removed.
-
-> `g.V()` is to get all the vertices, `g.E()` is to get all the edges,
`toList()` is to store the result in a List, refer to [TinkerPop Terminal
Steps](http://tinkerpop.apache.org/docs/current/reference/#terminal-steps)。
-
-Enter the gremlin-console below and pass in the script to execute it:
+Then enter the following command:
```bash
> ./bin/gremlin-console.sh -- -i scripts/example.groovy
@@ -97,7 +43,9 @@ gremlin>
> The `--` here will be parsed by getopts as the last option, allowing the
> subsequent options to be passed to Gremlin-Console for processing. `-i`
> represents `Execute the specified script and leave the console open on
> completion`. For more options, you can refer to the [source
> code](https://github.com/apache/tinkerpop/blob/3.5.1/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy#L483)
> of Gremlin-Console.
-As you can see, 6 vertices and 6 edges are inserted and queried. After
entering the console, you can continue to enter groovy statements to operate on
the graph:
+[`example.groovy`](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-dist/src/assembly/static/scripts/example.groovy)
is an example script under the `scripts` directory. This script inserts some
data and queries the number of vertices and edges in the graph at the end.
+
+You can continue to enter Gremlin statements to operate on the graph:
```groovy
gremlin> g.V()
@@ -123,7 +71,7 @@ For more Gremlin statements, please refer to [Tinkerpop
Official Website](http:/
Because Gremlin-Console can only connect to HugeGraph-Server through
WebSocket, HugeGraph-Server provides HTTP connections by default, so modify the
configuration of gremlin-server first.
-*NOTE: After changing the connection method to WebSocket, HugeGraph-Client,
HugeGraph-Loader, HugeGraph-Hubble and other supporting tools cannot be used.*
+**NOTE: After changing the connection method to WebSocket, HugeGraph-Client,
HugeGraph-Loader, HugeGraph-Hubble and other supporting tools cannot be used.**
```yaml
# vim conf/gremlin-server.yaml
@@ -136,7 +84,7 @@ channelizer:
org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
Modify `channelizer:
org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer` to `channelizer:
org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer` or comment
directly, and then follow the [steps](/docs/quickstart/hugegraph-server/) to
start the Server.
-Then enter gremlin-console:
+Then enter Gremlin-Console:
```bash
> ./bin/gremlin-console.sh
@@ -170,7 +118,7 @@ gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
```
-After a successful connection, if the sample graph `example.groovy` is
imported during the startup of HugeGraphServer, you can directly perform
queries in the console.
+After a successful connection, if the sample graph `example.groovy` is
imported during the startup of HugeGraph-Server, you can directly perform
queries in the console.
```groovy
gremlin> :> hugegraph.traversal().V()
@@ -202,4 +150,4 @@ gremlin> :> @script
gremlin>
```
-For more information on the use of gremlin-console, please refer to [Tinkerpop
Official Website](http://tinkerpop.apache.org/docs/current/reference/)
+For more information on the use of Gremlin-Console, please refer to [Tinkerpop
Official Website](http://tinkerpop.apache.org/docs/current/reference/)