0
votes

I need to get vertices filtered by a specific predicate on the properties, and all the edges (with a particular label, and perhaps some predicate on the properties of an edge) existing between them.

This is for a Cosmos Azure Db graph, and the solution should be a single Gremlin query.

So far I am thinking of something along the lines of:

g.V().has('property1', value1).has('property2', value2).select('vertices')
.outE().as('edges').inV().has('property1', value1).has('property2', value2)
.select('vertices','edges')

Is there a better way to achieve this?

1
I think without a real sample its hard to answer you. If this query give you the exact outcome you want? Is the edges you looking always connected to the vertex with property 1 and property 2? Maybe project will give you a better results but you need to give example what you trying to achieve.noam621
They might not be always connected. What I want is to select all the vertices with required properties and then see if there are specific edges between them. If so output the edges as well as the vertices connected by them.Anton Klimov

1 Answers

0
votes

Given the description and your comment, this traversal should work for you:

g.V().has('property1', value1).has('property2', value2).
  aggregate('v').
  outE().                   /* add edge filters here */
  inV().where(within('v')).
  path().
  union(union(limit(local, 1),
              tail (local, 1)).dedup().aggregate('vertices'),
        range(local, 1, 2).aggregate('edges')).
  cap('vertices','edges').next()