Tinkerpop:select 个顶点没有到具有 属性 个顶点的路径
Tinkerpop: select vertex which do not have path to vertex having a property
在 Tinkerpop 中,我想要 select 不直接连接到具有 属性 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);
在上面的测试用例中,我想 select 所有 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, 'name', 'Two').
addV('Vertex').as('3').property(single, 'name', 'Three').
addV('Vertex').as('4').property(single, 'name', 'Four').
addV('Tag').as('5').property(single, 'name', 'Key1').
addV('Tag').as('6').property(single, 'name', 'Key2').
addV('Tag').as('7').property(single, 'name', 'Key3').
addE('connected').from('1').to('5').
addE('connected').from('2').to('6').
addE('connected').from('4').to('7')
Gremlify link: https://gremlify.com/f1muf12xhdv/2
您可以结合使用 not
和 where
步骤来实现此目的:
g.V().hasLabel('User').
not(where(out('user_tag').has('tagKey', 'tagKey2'))).
valueMap().with(WithOptions.tokens)
在 Tinkerpop 中,我想要 select 不直接连接到具有 属性 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);
在上面的测试用例中,我想 select 所有 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, 'name', 'Two').
addV('Vertex').as('3').property(single, 'name', 'Three').
addV('Vertex').as('4').property(single, 'name', 'Four').
addV('Tag').as('5').property(single, 'name', 'Key1').
addV('Tag').as('6').property(single, 'name', 'Key2').
addV('Tag').as('7').property(single, 'name', 'Key3').
addE('connected').from('1').to('5').
addE('connected').from('2').to('6').
addE('connected').from('4').to('7')
Gremlify link: https://gremlify.com/f1muf12xhdv/2
您可以结合使用 not
和 where
步骤来实现此目的:
g.V().hasLabel('User').
not(where(out('user_tag').has('tagKey', 'tagKey2'))).
valueMap().with(WithOptions.tokens)