无法打印DSE图中的节点属性

问题描述:

道歉,因为这可能是关于这个主题的非常基本的问题,但我是Gremlin/DSE Graph的新手,我尝试了很多方法来提取数据,我插入到我的图中,但不知何故,我无法使其工作。无法打印DSE图中的节点属性

以下是我的: 1.将allow_scans设置为true的图形 2.在所有顶点的NodeID上定义了propertyKey和顶点以及物化索引的模式。

现在没有关系,只是带有数据点的顶点。

我写了一个程序中插入我到DSE图中的所有节点,因为我得到回应像下面这是成功的工作程序创建的每个顶点后:

Result({u'id': {u'out_vertex': {u'community_id': 853347840, u'~label': u'vertex', u'member_id': 14}, u'~type': u'Name', u'local_id': u'00000000-0000-8012-0000-000000000000'}, u'value': u'amount', u'label': u'Name'})] 

好了所以,现在的节点被插入,我想提取它们并打印他们的名字: 所以我做:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').values('Name'); 

以上空白结果成功地失败了。我的意思是它运行成功,空输出像没有错误,但没有输出。 (在gremlin-console中为null,在DataStax Studio中为'成功 - 无结果')

然后我发现文档中图表不知道'has'是否只返回一个或多个节点,所以我用next来迭代按文档和教程:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').next().values('Name'); 

即使这样失败,

org.apache.tinkerpop.gremlin.driver.exception.ResponseException

(Datastax studio不显示更多信息) - 如何进一步调试?

我甚至在对面,我用地图拉姆达办法就来了:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').map{it.get().value('Name')}; 

与“它”没有被定义回应。

(我甚至试图valueMap - 不知道,甚至被要求它)

我究竟做错了查找和打印属性节点的值?

任何可以帮助我提取名称和其他属性的方向或查询?即使是多步查询?但我不认为这应该是那么复杂。

UPDATE

按答案我得到以下回溯:

gremlin> :> g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').valueMap(true).next(); 
org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException 
Type ':help' or ':h' for help. 
Display stack trace? [yN]y 
org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException 
     at org.apache.tinkerpop.gremlin.console.groovy.plugin.DriverRemoteAcceptor.submit(DriverRemoteAcceptor.java:170) 
     at org.apache.tinkerpop.gremlin.console.commands.SubmitCommand.execute(SubmitCommand.groovy:41) 
     at org.codehaus.groovy.tools.shell.Shell.execute(Shell.groovy:104) 
     at org.codehaus.groovy.tools.shell.Groovysh.super$2$execute(Groovysh.groovy) 
     at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:498) 
     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) 
     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) 
     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215) 
     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132) 
     at org.codehaus.groovy.tools.shell.Groovysh.executeCommand(Groovysh.groovy:259) 
     at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.execute(GremlinGroovysh.groovy:84) 
     at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:122) 
     at org.codehaus.groovy.tools.shell.ShellRunner.work(ShellRunner.groovy:95) 
     at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:498) 
     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) 
     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) 
     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215) 
     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132) 
     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152) 
     at org.codehaus.groovy.tools.shell.InteractiveShellRunner.work(InteractiveShellRunner.groovy:124) 
     at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:59) 
     at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:498) 
     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) 
     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) 
     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215) 
     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132) 
     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152) 
     at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:83) 
     at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232) 
     at org.apache.tinkerpop.gremlin.console.Console.<init>(Console.groovy:152) 
     at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232) 
     at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:401) 

我能够在其他图形做一些类似的操作。图表有问题吗?

更新2

我图的顶点被错误地定义。

深入解决此问题的关键在于结果中的~label。它指向vertex而不是它应该是Field

定义数据插入组时,必须将标签放在引号中,以便不得不提及引号时提及标签。因此我无法遍历节点。

您需要确保迭代遍历。最常见的是你可以使用两种:

  • iterate()得到零结果
  • next()得到一个结果
  • toList()得到很多结果

我猜NodeID是独一无二的,所以你可以试试这:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06'). 
values('Name').next(); 

如果你'重新在该顶点的所有属性感兴趣,请尝试:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06'). 
valueMap(true).next(); 
+0

谢谢你的回答,我更新了我所得到的跟踪。看起来像图表有些问题。请你能帮我找出这里可能是什么问题。 ('FIELD')。has('NodeID','2559b635f077e86c7370ab1c4c798a06')。 values('Name')在具有相似节点的另一个图中工作。不知道这一个出了什么问题。 – Nik

+0

我的顶点是以错误的方式定义的。你的回答是正确的。谢谢 – Nik