透過Gremlin Python建立索引(Tinkerpop)

2024-09-28 05:25:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前使用的是带有默认TinkerGraph-Gremlin(在内存中运行)的gremlin python client的修补程序。我想提高查询的性能,并阅读createIndex()函数,这听起来是我的用例的完美之选,遗憾的是我无法用python客户机创建索引。我还尝试将这些行添加到启动的groovy脚本中(在groovy scirpt中运行,没有错误),但是当我运行性能基准测试时,我得到了相同的结果。在

所以我的问题是:我能用python客户机创建一个索引吗?如果不能,有什么解决办法?还有没有一种方法可以询问gremlin是否定义了任何索引?在

注:对于groovy脚本,我使用了默认的empty-sample.grooy,并在最后一次调用之前添加以下行:

graph.createIndex("name", Vertex.class)
graph.createIndex("nap", Edge.class)

谢谢!在


Tags: 函数内存程序脚本client客户机用例性能
2条回答

使用gremlinpython v3.2.6

搜索TinkerPop的github,我发现你可以直接发送请求,因为它是使用客户机对象的数据库控制台。这种行为在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。在

python客户端没有createIndex()方法,因为TinkerPop在3.x中没有对索引提供任何抽象。我们依赖于底层图形数据库的索引和模式创建方法。你必须降低到API级别,脱离修补程序。在

如果只确定是否使用查询速度创建索引,请记住,图中只有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

相关问题 更多 >

    热门问题