【问题标题】:Gremlin Python createIndex (Tinkerpop)Gremlin Python createIndex (Tinkerpop)
【发布时间】:2017-04-27 07:31:31
【问题描述】:

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

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

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

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

谢谢!

【问题讨论】:

  • 这两种方法都应该有效。出于好奇,您的图表有多大?
  • @stephenmallette 问题是在 python 客户端中缺少 createIndex() 方法(据我所知)。并将这两行添加到 groovy 脚本中会导致相同的查询时间。大约 8000 个顶点。

标签: python gremlin tinkerpop


【解决方案1】:

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

【讨论】:

  • 感谢您的快速回复!我再次检查了图表:g.V().count().next() 16000g.E().count().next() 31000。最后一个问题:如果我在name 上创建索引,我应该始终先选择name 并使用has('name', xxx) 语句?
  • 使用 TinkerGraph,您应该将最具选择性的索引属性放在首位。其他图表可能表现不同,并且在优化一系列has() 步骤方面做得更好。
【解决方案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 中有详细说明。

【讨论】:

    猜你喜欢
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多