Gremlin Python createIndex (小叮当)
Gremlin Python createIndex (Tinkerpop)
我目前正在将 Tinkerpop 与 gremlin python client with the default TinkerGraph-Gremlin(在 运行ning 内存中)一起使用。我想提高查询的性能并阅读了 createIndex()
函数,这听起来非常适合我的用例,遗憾的是我无法使用 python 客户端创建索引。我还尝试将这些行添加到启动 groovy 脚本中(运行 通过 groovy scirpt 没有错误)但是当我 运行 我的性能基准我得到相同的结果。
所以我的问题是:我可以使用 python 客户端创建索引吗?如果不能,有什么解决方法?还有没有办法询问 gremlin 是否定义了任何索引?
PS.: 对于 groovy 脚本,我使用默认的 empty-sample.grooy
并在最后一次调用之前添加这些行:
graph.createIndex("name", Vertex.class)
graph.createIndex("nap", Edge.class)
谢谢!
python 客户端将没有 createIndex()
方法,因为 TinkerPop 不提供任何对 3.x 中索引的抽象。我们依赖底层图数据库的索引和模式创建方法。您必须下降到 API 级别并退出 TinkerPop。
如果您只是确定是否使用查询速度创建索引,请记住您的图形中只有 8800 个顶点,并且 TinkerGraph 是内存中的图形。您可能看不到这么少的顶点在速度上有明显的差异。如果您想知道您的索引是否已创建,只需查找即可:
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> graph.createIndex('name',Vertex.class)
gremlin> graph.getIndexedKeys(Vertex.class)
==>name
使用 gremlinpython v3.2.6
搜索 github 的 TinkerPop,我发现您可以发送直接请求,因为它是使用客户端对象的数据库控制台。 the GitHub of Tinkerpop 中解释了此行为。我将展示同步版本,在 GitHub 中还有一个异步版本:
from gremlin_python.driver.client import Client
client = Client(url, travelsal_source)
console_command_string = "2*2" # Write code as it was the console of the database you're using
result_set = client.submit(console_command_string)
future_results = result_set.all()
results = future_results.result()
client.close()
要查看您必须发送什么命令,请查看您正在使用的确切数据库,如果是 Janusgraph,its indexing documentation 中有详细说明。
我目前正在将 Tinkerpop 与 gremlin python client with the default TinkerGraph-Gremlin(在 运行ning 内存中)一起使用。我想提高查询的性能并阅读了 createIndex()
函数,这听起来非常适合我的用例,遗憾的是我无法使用 python 客户端创建索引。我还尝试将这些行添加到启动 groovy 脚本中(运行 通过 groovy scirpt 没有错误)但是当我 运行 我的性能基准我得到相同的结果。
所以我的问题是:我可以使用 python 客户端创建索引吗?如果不能,有什么解决方法?还有没有办法询问 gremlin 是否定义了任何索引?
PS.: 对于 groovy 脚本,我使用默认的 empty-sample.grooy
并在最后一次调用之前添加这些行:
graph.createIndex("name", Vertex.class)
graph.createIndex("nap", Edge.class)
谢谢!
python 客户端将没有 createIndex()
方法,因为 TinkerPop 不提供任何对 3.x 中索引的抽象。我们依赖底层图数据库的索引和模式创建方法。您必须下降到 API 级别并退出 TinkerPop。
如果您只是确定是否使用查询速度创建索引,请记住您的图形中只有 8800 个顶点,并且 TinkerGraph 是内存中的图形。您可能看不到这么少的顶点在速度上有明显的差异。如果您想知道您的索引是否已创建,只需查找即可:
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> graph.createIndex('name',Vertex.class)
gremlin> graph.getIndexedKeys(Vertex.class)
==>name
使用 gremlinpython v3.2.6
搜索 github 的 TinkerPop,我发现您可以发送直接请求,因为它是使用客户端对象的数据库控制台。 the GitHub of Tinkerpop 中解释了此行为。我将展示同步版本,在 GitHub 中还有一个异步版本:
from gremlin_python.driver.client import Client
client = Client(url, travelsal_source)
console_command_string = "2*2" # Write code as it was the console of the database you're using
result_set = client.submit(console_command_string)
future_results = result_set.all()
results = future_results.result()
client.close()
要查看您必须发送什么命令,请查看您正在使用的确切数据库,如果是 Janusgraph,its indexing documentation 中有详细说明。