0

with Neptune + nodejs

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

returns:

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

how can I do a filter so it only returns:

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

I tried

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

but it throws error UnsupportedOperationException

I also tried g.V().hasLabel('Device').where(properties().value().is(containing('b')))

same error, but i think it is because i have different data type in multiple properties, the containing method failed when it come across number type.....

Zhongmin
  • 1,684
  • 1
  • 16
  • 33

2 Answers2

1

You probably do not need to use properties unless you are planning to do something like drop the property. You should be able to simply do:

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

I am assuming that "value" is the name of your property. If it is not please clarify.

EDITED to add more examples.

If you wanted to test all properties you could do something like this which wil find the matching properties.

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]

If you want the vertex that contains the properties

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

==>v[14b93051-dece-db72-9f46-46df7513a14c]
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • I actually have a requirement to query all the properties, any properties contains 'xyz', is there a way to replace your example 'value' to be all properties? – Zhongmin May 29 '20 at 04:50
  • I added more examples that show how to retrieve either the matching properties or the vertices that contain those properties. – Kelvin Lawrence May 29 '20 at 13:41
  • the query fails if the properties contain different type of data, e.g. number, I think this is a known issue – Zhongmin Jun 01 '20 at 23:26
  • Yes. There is an issue open on the ApacheTinkerpop Jira for that when using the TextP predicates. – Kelvin Lawrence Jun 01 '20 at 23:41
0

You can use filter :

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

or

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

EDIT: This query works in pure Gremlin not Neptune version.

mehmet sahin
  • 802
  • 7
  • 21
  • It is desirable to avoid using closures in general and stick to pure Gremlin steps. As the OP is using Amazon Neptune this is especially so as Groovy closures in queries are not supported. – Kelvin Lawrence May 28 '20 at 15:29