我开始使用REST API使用Neo4j进行开发.我看到有两个选项可用于执行复杂查询 - Cypher(Neo4j的查询语言)和Gremlin(通用图形查询/遍历语言).
这就是我想知道的 - 有没有任何查询或操作可以通过使用Gremlin完成,而不能用Cypher完成?或相反亦然?
Cypher对我来说似乎比Gremlin要清楚得多,而且一般来说Neo4j中的人似乎都会选择Cypher.但是 - 如果Cypher与Gremlin相比有限 - 我真的很想提前知道.
我知道如何通过id删除顶点,但我需要删除多个顶点(清理数据库).
删除1 v是这样的:
ver = g.v(1)
g.removeVertex(ver)
Run Code Online (Sandbox Code Playgroud) 我已经和Titan图形服务器玩了一段时间了.我的感觉是,尽管有大量文档,但缺乏从头开始入门教程.
我的最终目标是让一个巨人在cassandra上运行并使用StartTheShift/thunderdome进行查询.
我见过几种启动泰坦的方法:
从这个链接,我能够通过以下步骤运行titan服务器:
titan-all-0.3.0/libs
到rexster-server-2.3.0/ext/titan
编辑rexster-server-2.3.0/rexster.xml
和添加(在a之间):
<graph>
<graph-name>geograph</graph-name>
<graph-type>com.thinkaurelius.titan.tinkerpop.rexster.TitanGraphConfiguration</graph-type>
<graph-read-only>false</graph-read-only>
<graph-location>/Users/vallette/projects/DATA/gdb</graph-location>
<properties>
<storage.backend>local</storage.backend>
<storage.directory>/Users/vallette/projects/DATA/gdb</storage.directory>
<buffer-size>100</buffer-size>
</properties>
<extensions>
<allows>
<allow>tp:gremlin</allow>
</allows>
</extensions>
</graph>
Run Code Online (Sandbox Code Playgroud)对于berkeleydb或:
<graph>
<graph-name>geograph</graph-name>
<graph-type>com.thinkaurelius.titan.tinkerpop.rexster.TitanGraphConfiguration</graph-type>
<graph-location></graph-location>
<graph-read-only>false</graph-read-only>
<properties>
<storage.backend>cassandra</storage.backend>
<storage.hostname>77.77.77.77</storage.hostname>
</properties>
<extensions>
<allows>
<allow>tp:gremlin</allow>
</allows>
</extensions>
</graph>
Run Code Online (Sandbox Code Playgroud)
对于cassandra db.
./bin/rexster.sh -s -c rexster.xml
bin/rexster-console.sh
g = rexster.getGraph("geograph")
这种方法的问题是你通过rexster而不是gremlin连接,所以你没有自动完成.优点是您可以命名您的数据库(此处为地理位置).
./bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
创建一个名为cassandra.local
with …
我无法创建索引.我的Gremlin代码如下:
usernameProperty = mgmt.getPropertyKey('username')
usernameIndex = mgmt.buildIndex('byUsernameUnique', Vertex.class).addKey(usernameProperty).unique().buildCompositeIndex()
mgmt.setConsistency(usernameIndex, ConsistencyModifier.LOCK)
mgmt.commit()
Run Code Online (Sandbox Code Playgroud)
我收到两个错误后不久:
18:04:57 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - 从缓存中驱逐[1 @ 0a00009d2537-ip-10-0-0-1572]但等待交易结束的时间太长.过时的交易警报:[standardtitantx [0x6549ce71]] 18:04:57 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - 从缓存中驱逐[1 @ 0a00009d2537-ip-10-0-0-1572]但是等待交易结束的时间过长.过时的交易警报:[standardtitantx [0x2a2815cc],standardtitantx [0x025dc2c0]]
索引的状态停留在INSTALLED
:
usernameIndex.getIndexStatus(usernameProperty)
==>INSTALLED
Run Code Online (Sandbox Code Playgroud)
我读到失败的实例可能会导致问题,但检查正在运行的实例只显示一个:
mgmt.getOpenInstances()
==>0a00009d3011-ip-10-0-0-1572(current)
Run Code Online (Sandbox Code Playgroud)
我也尝试发布一个REGISTER_INDEX
动作,它也会从事务缓存中逐出,并带有类似的错误消息:
mgmt.updateIndex(usernameIndex, SchemaAction.REGISTER_INDEX).get()
mgmt.commit()
Run Code Online (Sandbox Code Playgroud)
我也尝试过多次重启服务器.
注册过程似乎只是超时,导致事务缓存"逐出".我等了48个小时才确定这不是一个缓慢的过程.对Titan的正常读取,写入和关联提交似乎工作正常,我只是无法创建此索引.我被卡住了,还有什么我可以尝试的吗?有没有办法延长该事务的超时?
我正在使用DynamoDB后端运行Titan 1.0.0(使用AWS提供的CloudFormation模板进行设置).
编辑:这是我正在粘贴Gremlin的完整命令,添加awaitGraphStatus
了@MTA建议的步骤:
mgmt = graph.openManagement();
usernameIndex = mgmt.getPropertyKey('usernameIndex');
mgmt.buildIndex('byUsername',Vertex.class).addKey(usernameIndex).unique().buildCompositeIndex();
// I have tried with and without a commit here: mgmt.commit();
mgmt.awaitGraphIndexStatus(graph, 'byUsername').status(SchemaStatus.REGISTERED).timeout(10, java.time.temporal.ChronoUnit.MINUTES).call();
Run Code Online (Sandbox Code Playgroud)
这会导致以下错误:
com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher.call(GraphIndexStatusWatcher.java:52)中的java.lang.NullPointerException,地址为com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher.call(GraphIndexStatusWatcher.java:18) )atg.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)中的java_util_concurrent_Callable $ call.call(未知来源)atg.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java) :110)org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114)at groovysh_evaluate.run(groovysh_evaluate:3)at …
我正在使用groovy(gremlin准确地遍历图形数据库).不幸的是,因为我使用的是gremlin,所以我无法导入新的类.
我有一些日期值,我希望转换为Unix时间戳.它们以以下格式存储为UTC:2012-11-13 14:00:00:000
我正在使用这个片段解析它(在groovy中):
def newdate = new Date().parse("yyyy-M-d H:m:s:S", '2012-11-13 14:00:00:000')
Run Code Online (Sandbox Code Playgroud)
问题是它进行了时区转换,结果是:
Tue Nov 13 14:00:00 EST 2012
Run Code Online (Sandbox Code Playgroud)
如果我然后将其转换为使用时间戳time()
,转换为UTC,则生成时间戳.
如何new Date()
在首次解析日期时进行任何时区转换(并假设日期为UTC)?
是否可以使用Azure Cosmos Graph DB中的包含搜索顶点属性?
例如,我想找到所有'Jr'
以他们名义的人?
g.V().hasLabel('person').has('name',within('Jr')).values('name')
Run Code Online (Sandbox Code Playgroud)
似乎该within('')
函数仅过滤完全相等的值'Jr'
.我正在寻找一个包含.理想情况下不区分大小写.
如何使用 Gremlin 更新图中节点的现有属性?
以下方法创建两个具有 2 个不同值的属性“timestamp”,而不是更新现有属性“timestamp”:
ContentGraph.g.addV('Filter').property('timestamp', new Date());
ContentGraph.g.V().hasLabel('Filter').property('timestamp', new Date());
Run Code Online (Sandbox Code Playgroud) 这是你如何使用Gremlin对Neo4j图表进行排序(排序)的方法:
g.v(id).out('knows').sort{it.name}
Run Code Online (Sandbox Code Playgroud)
要么
g.v(id).out('knows').sort{a,b -> a.name <=> b.name}
Run Code Online (Sandbox Code Playgroud)
这是如何使用偏移/跳过和限制来限制结果:
g.v(id).out('knows')[0..9]
Run Code Online (Sandbox Code Playgroud)
但是,如果将sort和limit结合使用
g.v(id).out('knows').sort{it.name}[0..9]
Run Code Online (Sandbox Code Playgroud)
它会引发错误......
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList$ListItr.getAt() is applicable for argument types: (groovy.lang.IntRange) values: [0..9]
Possible solutions: getAt(java.lang.String), getAt(int), next(), mean(), set(java.lang.Object), putAt(java.lang.String, java.lang.Object)
Run Code Online (Sandbox Code Playgroud) 我目前正在为neo4j使用嵌入式python绑定.我目前没有任何问题,因为我的图表非常小(稀疏和高达100个节点).我正在开发的算法在图上涉及相当多的遍历,更具体地说是图上的DFS以及不同的子图.在未来,我打算在大图上运行算法(据说是稀疏的,有数百万个节点).
有与python /的Neo4j绑定的性能阅读不同的线程在这里,在这里,我不知道我是否应该已经切换到一些REST API客户端的Python(如bulbflow,py2neo,neo4jrestclient),直到我太远改变所有代码.
不幸的是,我没有找到任何综合的信息来源来比较不同的方法.
任何人都可以进一步了解这个问题吗?选择其中一个选项时,我应该考虑哪些标准?
在Tinkerpop 3中,如何进行分页?我想获取查询的前10个元素,然后接下来的10个元素而不必将它们全部加载到内存中.例如,下面的查询返回1000,000条记录.我想在不加载所有1000,000的情况下以10×10的速度获取它们.
g.V().has("key", value).limit(10)
Run Code Online (Sandbox Code Playgroud)
HttpChannelizer
在Gremlin Server上运行的解决方案将是理想的选择.