如何在gremlin查询的has步中测试Boolean属性的值?

问题描述 投票:0回答:1

我已经定义了一个带有模式的Vertex,并且顶点的几个属性都是boolean类型。我现在正在尝试查询顶点并按照这些属性的布尔值过滤结果。

我试过了:

g.V().hasLabel('Patient').has('alcohol_abuse', eq(true))
g.V().hasLabel('Patient').has('alcohol_abuse', true)
g.V().hasLabel('Patient').has('alcohol_abuse', constant(true))
g.V().hasLabel('Patient').has('alcohol_abuse', eq(1))

加上更多变化,没有返回正确的结果

我希望使用属性alcohol_abuse为true来获取Patient顶点中的顶点。

谢谢

gremlin traversal janusgraph
1个回答
1
投票

这很奇怪 - 这个:

g.V().hasLabel('Patient').has('alcohol_abuse', true)

或者更简洁,这个:

g.V().has('Patient', 'alcohol_abuse', true)

应该管用。我用TinkerGraph做了一个快速测试:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('Patient').property('alcohol_abuse',true).
......1>   addV('Patient').property('alcohol_abuse',false).iterate()
gremlin> g.V().has('Patient','alcohol_abuse',true).count()
==>1
gremlin> g.V().has('Patient','alcohol_abuse',false).count()
==>1

所以这绝对是包括JanusGraph在内的所有TinkerPop实现的预期结果。如果您没有看到问题的解决方案,则可能需要发布Gremlin控制台会话的文本以进行演示。

© www.soinside.com 2019 - 2024. All rights reserved.