Re: hey guys ,how to query a person relational depth


Jason Plurad <plu...@...>
 

Use simplePath() to avoid cycles http://tinkerpop.apache.org/docs/current/reference/#simplepath-step

gremlin> graph = JanusGraphFactory.open('inmemory'); g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[inmemory:[127.0.0.1]], standard]
gremlin
> g.addV().property('name', 'A').as('a').
......1>            addV().property('phone', '110').as('b').
......2>            addV().property('name', 'C').as('c').
......3>            addV().property('phone', '111').as('d').
......4>            addV().property('name', 'E').as('e').
......5>            addV().property('phone', '112').as('f').
......6>            addV().property('name', 'G').as('g').
......7>            addE('hasPhone').from('a').to('b').
......8>            addE('hasPhone').from('c').to('d').
......9>            addE('hasPhone').from('c').to('b').
.....10>            addE('hasPhone').from('e').to('d').
.....11>            addE('hasPhone').from('e').to('f').
.....12>            addE('hasPhone').from('g').to('b').iterate()
gremlin
> g.V().has('name', 'A').repeat(both().simplePath()).emit().path().count(local).max()
11:11:58 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - Query requires iterating over all vertices [(name = A)]. For better performance, use indexes
==>6



On Wednesday, August 23, 2017 at 10:26:12 PM UTC-4, 李平 wrote:
gremlin> g.addV().property('name', 'A').as('a'). addV().property('phone', '110').as('b'). addV().property('name', 'C').as('c'). addV().property('phone', '111').as('d'). addV().property('name', 'E').as('e'). addV().property('phone', '112').as('f'). addV().property('name', 'G').as('g'). addE('hasPhone').from('a').to('b'). addE('hasPhone').from('c').to('d'). addE('hasPhone').from('c').to('b'). addE('hasPhone').from('e').to('d').
addE('hasPhone').from('e').to('f'). addE('hasPhone').from('g').to('b').iterate()



if I want to know vertex A's relation depth how to write the gremlin commond,   

I  write like this 

g.V().has('userId','1').repeat(__.as("a").out().in().where(neq("a"))).emit().path().count(local).max()



but it seem endless loop,
在 2017年8月23日星期三 UTC+8下午9:16:21,Jason Plurad写道:
There's a recipe for this http://tinkerpop.apache.org/docs/current/recipes/#_maximum_depth

On Wednesday, August 23, 2017 at 3:52:14 AM UTC-4, 李平 wrote:
I want to know ,one person in the janusGraph ,his relational depth,use gremlin

Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.