Gremlin usage- Show edge property in the result set

1,742 views
Skip to first unread message

Meg

unread,
Apr 23, 2013, 6:02:58 PM4/23/13
to gremli...@googlegroups.com

I have the vertices connected as shown in picture above. My question is how do I create Gremlin query to get Tagtype's nodeTypes with edge property (order value) when I have BizView db_id.

The query I wrote:
t = new Table();t1 = new Table();g.V('type', 'biz_view').has("db_id",9).as('bv').table(t){it.db_id}.out('has').as('tag_type').table(t1,['bv','tag_type']){it.db_id}{it.node_type}



Gives me the TagTypes which are connected to Bizview with db_id 9 as shown above. How do I modify query to get the edge order as well. Thank you.


Meg




Daniel Kuppitz

unread,
Apr 23, 2013, 6:38:09 PM4/23/13
to gremli...@googlegroups.com
Hi Meg,

I've used the following queries to initialize the graph for testing:

conf = new BaseConfiguration();
conf.setProperty("storage.backend","inmemory");

g = TitanFactory.open(conf)

v1 = g.addVertex(['type':'biz_view','db_id':9,'name':'Biz11'])
v2 = g.addVertex(['type':'biz_view','db_id':10,'name':'Biz2'])
v3 = g.addVertex(['type':'tag_type','tag_type':'tag_type8'])
v4 = g.addVertex(['type':'tag_type','tag_type':'tag_type9'])
v5 = g.addVertex(['type':'tag_type','tag_type':'tag_type10'])
e1 = v1.addEdge('has', v4)
e2 = v1.addEdge('has', v5)
e3 = v2.addEdge('has', v5)
e4 = v2.addEdge('has', v3)
e1.setProperty('order', 2)
e2.setProperty('order', 1)
e3.setProperty('order', 1)
e4.setProperty('order', 2)

Then the query you are looking for should be somthing like this:

gremlin> g.V('type','biz_view').has('db_id',9).db_id.as('bv').back(1).outE('has').property('order').as('order').back(1).inV().tag_type.as('tag_type').table().cap()
==>[[bv:9, order:2, tag_type:tag_type9], [bv:9, order:1, tag_type:tag_type10]]

If it's not what you need: Please provide an init script with some sample data and the result that you expect.

Cheers,
Daniel

Meg

unread,
Apr 24, 2013, 12:30:58 PM4/24/13
to gremli...@googlegroups.com
Thanks Daniel. It worked.
Meg
Reply all
Reply to author
Forward
0 new messages