First select all vertices of Group a, then the matching vertices of Group b and finally link them together:
g.V().hasNot("BaseRecId", null).hasNot("GroupName", null).as("a").transform({
g.V("BaseRecId", it.getProperty("BaseRecId")).hasNot("SalesRecId", null)
}).scatter().linkIn("label", "a")
Assumptions in this query:
- each vertex in Group a has a GroupName
- each vertex in Group b has a SalesRecId
- BaseRecId is indexed (this is optional, but would speed things dramatically up)
This should work for a small graph. For larger graphs use Faunus.