mano haran
mano haran

Reputation: 89

How to exclude certain vertices in gremlin titan

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.

Upvotes: 2

Views: 1463

Answers (2)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

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))

Upvotes: 4

Florian Hockmann
Florian Hockmann

Reputation: 2819

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.

Upvotes: 1

Related Questions