如何使用Neptune + nodejs中的值过滤属性

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

使用Neptune + nodejs

g.V().hasLabel('A').properties()

返回:

id, label, value
1, 'p1','v1'
2, 'p1','b2'
3, 'p1','b3'
4, 'p1','d4'

我该如何做一个过滤器,使其仅返回:

id, label, value
2, 'p1','b2'
3, 'p1','b3'

我尝试过

g.V().hasLabel('Device').properties().value().is(containing('b'))

但是会引发错误UnsupportedOperationException

我也尝试过g.V().hasLabel('Device').where(properties().value().is(containing('b')))

相同错误,但我认为这是因为我在多个属性中具有不同的数据类型,当遇到数字类型时,包含方法失败.....

gremlin amazon-neptune
2个回答
1
投票

除非您计划进行删除属性之类的操作,否则可能不需要使用properties。您应该能够做到:

g.V().hasLabel('Device').has('value',containing('b'))

我假设“值”是您的财产的名称。如果不是,请澄清。

编辑以添加更多示例。

如果您想测试所有属性,则可以执行类似的操作以找到匹配的属性。

gremlin> g.addV('test').property('x','Hello').
                        property('y','Another one').
           addV('test').property('y','Goodbye')

==>v[12b93051-decf-3be5-85cd-cbc4c27e42f9]

g.V().hasLabel('test').
      properties().hasValue(TextP.containing('ll'))

==>vp[x->Hello]

如果要包含属性的顶点

gremlin> g.V().hasLabel('test').
             where(properties().hasValue(TextP.containing('ll')))

==>v[14b93051-dece-db72-9f46-46df7513a14c]

0
投票

您可以使用filter

g.V().hasLabel('Device').filter({ it.getProperty("value").startsWith("b") })

g.V().hasLabel('Device').filter({ it.getProperty("value").contains("b") })

编辑:此查询在纯Gremlin而非Neptune版本中有效。

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