Find by property value

20 views
Skip to first unread message

Bidhan Khanal

unread,
Jan 26, 2023, 5:29:28 PM1/26/23
to Gremlin-users
Graph graph= TinkerGraph.open();

graph.addVertex("Player")
.property("Name","Messi")
.property("Club","PSG");
graph.addVertex("Player")
.property("Name","Neymar")
.property(" Club  ","PSG");
graph.addVertex("Player")
.property("Name","Ronaldo")
.property(" Club  ","Al-Nassr");

GraphTraversalSource g = graph.traversal();

Now , I need All the player of PSG club.
Expected output = [Messi , Neymar]

Please help

Taylor Riggan

unread,
Jan 27, 2023, 9:32:11 AM1/27/23
to Gremlin-users
A really good resource to learn the Gremlin query language can be found here:  https://www.kelvinlawrence.net/book/PracticalGremlin.html

A couple things about your question:

#1 - you shouldn't use the addVertex() method from the graph class.  This is mostly internal and a lot of TinkerPop-enabled graph databases do not even expose the instantiated graph object.  Instead, you should use the addV() or addE() steps off of the graph traversal object (g) that you've created:

g.addV("Player").
    property("Name","Messi").
    property("Club","PSG").
addV("Player").
    property("Name","Neymar").
    property("Club","PSG").
addV("Player").
    property("Name","Ronaldo").
    property("Club","Al-Nassr")
//if using Gremlin within a supported programming language, you'll need to end this with a Terminal Step [1].  If in the Gremlin Console, you can end here.
.next()

#2 - to filter on a player by the 'Club' property, you would use the has() step [2] and values() step to fetch the property values that you want:

g.V().has("Club","PSG").values("Name")
// .toList()

Reply all
Reply to author
Forward
0 new messages