问题描述
在Tinkerpop中,我要选择不直接连接到属性foo
等于bar
的顶点的顶点
例如:
Vertex user1 = graph.addVertex("vid","one");
Vertex user2 = graph.addVertex("vid","two");
Vertex user3 = graph.addVertex("vid","three");
Vertex tag1 = graph.addVertex("tagKey","tagKey1");
Vertex tag2 = graph.addVertex("tagKey","tagKey2");
Vertex tag3 = graph.addVertex("tagKey","tagKey3");
user1.addEdge("user_tag",tag1);
user2.addEdge("user_tag",tag2);
user2.addEdge("user_tag",tag3);
在上述测试用例中,我想选择所有未连接到user
且值为tagKey
的标签顶点的tagKey2
顶点。输出应为2个顶点user3,user 1
解决方法
查询以获取未连接到标签的顶点。
g.V().hasLabel("Vertex").
filter(
not(outE().hasLabel('connected'))
).
properties()
查询以添加顶点数据:
g.addV('Vertex').as('1').property(single,'name','One').
addV('Vertex').as('2').property(single,'Two').
addV('Vertex').as('3').property(single,'Three').
addV('Vertex').as('4').property(single,'Four').
addV('Tag').as('5').property(single,'Key1').
addV('Tag').as('6').property(single,'Key2').
addV('Tag').as('7').property(single,'Key3').
addE('connected').from('1').to('5').
addE('connected').from('2').to('6').
addE('connected').from('4').to('7')
Gremlify链接:https://gremlify.com/f1muf12xhdv/2
,您可以结合使用not
和where
步骤来实现此目的:
g.V().hasLabel('User').
not(where(out('user_tag').has('tagKey','tagKey2'))).
valueMap().with(WithOptions.tokens)