Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gremlin Python createIndex(Tinkerpop)_Python_Gremlin_Tinkerpop - Fatal编程技术网

Gremlin Python createIndex(Tinkerpop)

Gremlin Python createIndex(Tinkerpop),python,gremlin,tinkerpop,Python,Gremlin,Tinkerpop,我目前正在使用带有默认值的Tinkerpop(在内存中运行)。我想提高查询的性能,并阅读有关createIndex()函数的内容,该函数听起来非常适合我的用例,遗憾的是,我无法使用python客户端创建索引。我还尝试将这些行添加到启动的groovy脚本中(在groovy scirpt中运行时没有错误),但是当我运行性能基准测试时,我得到了相同的结果 所以我的问题是:我能用python客户机创建索引吗?如果不能,解决方法是什么?还有没有办法问gremlin是否定义了任何索引 注:对于groovy脚

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

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

注:对于groovy脚本,我使用了默认的
空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

使用GremlinPythonV3.2.6

搜索TinkerPop的github,我发现您可以发送直接请求,因为它是使用客户机对象的数据库控制台。这一行为在中有解释。我将展示同步版本,在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,详细信息参见。

这两种方法都应该有效。出于好奇,您的图形有多大?@stephenmallette问题是python客户端缺少createIndex()方法(据我所知)。将这两行代码添加到groovy脚本中会导致相同的查询时间。大约8000个顶点。感谢您的快速回复!我再次检查了图表:
g.V().count().next()16000
g.E().count().next()31000
。最后一个问题:如果我在
name
上创建了一个索引,我应该总是用
has('name',xxx)
语句首先选择
name
?使用TinkerGraph,您应该将最具选择性的索引属性放在第一位。其他图形的行为可能会有所不同,并且在优化一系列
has()
步骤方面做得更好。