Suppose I have a list of attribute values as an ArrayList, How can I filter nodes by the values in the list.
Is something like this possible...
g.V().filter {it.get().value("name") in list}
also is it compatible with TinkerPop 2.x
On
You can simply use the has step for the filtering as it can take a list of values thanks to the within predicate:
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> names=['josh','peter']; g.V().has('name', within(names))
==>v[4]
==>v[6]
edit: My answer doesn't really address the question anymore as it now asks for a TinkerPop 2 solution. I'm still leaving it here in case anyone stumbles upon this question while looking for a solution for TinkerPop 3.
On
If the arrayList is part of existing traversal collected using store, you can use something like below.
Listing here in case someone runs into this situation.(like I did)
Say you have collection names collected in previous traversals and want to filter vertices based on that in subsequent traversal / steps.
g.V().out().store('names').by('name')
.out()
.where(within('names'))
.by('name')
.by()
.dedup()
...... further traversal
The above solution is derived from my question here answered by @Kelvin Lawrence
Using the
filter()step can work:Keep in mind that Titan 0.5.4 is quite dated (released in Feb 2015), and it depends on TinkerPop 2.5.0 (released in Apr 2014). Titan and TinkerPop 2.x are no longer under active development.
You should consider moving on to JanusGraph, which is a fork of Titan, has an active and open community, and is keeping current with the latest releases of Apache TinkerPop 3.x.