2
votes

For example I want to exclude some vertex ids while querying.

Step 1: I am taking user followed by me(1234):

g.V(1234).outE("following")

Output : 9876,3246,2343,3452,1233,6545


Step 2: I have to exclude or remove certain ids

users = [3452,1233,6545]; g.V(1234).outE("following").inV().except(users)

Output : 9876,3246,2343. It should come like this but the except function didn't work. Is there any solution to filter specific vertex ids.

2

2 Answers

4
votes

It's as easy as:

users = [3452, 1233, 6545]
g.V(1234).out("following").hasId(without(users))

Or just:

g.V(1234).out("following").hasId(without(3452, 1233, 6545))
1
votes

You can use the where step to filter the vertices. This allows you to exclude vertices based on their id. The following query should give you the expected result:

users = [3452,1233,6545];
g.V(1234).out("following").where(__.not(hasId(within(users))))

Note, that I used out() as a short form of outE().inV() which allows to directly traverse to the neighbor vertices.