The pictures attached define the schema used for the graph with the following counts, Total Nodes: 6.5 million, Total Edges: 3 million. Based on the selection of nodes and edges, I am creating the count queries.
For example: Node1, Relation1 and Node2 are selected. Query:
g.V().
has('property1', 'Node2').
filter(outE().has('property1', 'relation1')).
dedup().
aggregate('Node2').by(constant(1)).
outE().
has('property1', 'relation1').
dedup().
aggregate('relation1').by(constant(1)).
inV().
dedup().
aggregate('Node1').by(constant(1)).
count().
project('Node2', 'relation1', 'Node1').
by(select('Node2').unfold().sum()).
by(select('relation1').unfold().sum()).
by(select('Node1').unfold().sum())
Output:
==>[Node2:7003,relation1:200166,Node1:27690]
Time required to execute the query: approx 2 secs
I want to extend this query for multiple selections described as follows:
Case 1: Node1, Relation1, Node2, Node3 and Relation5 are selected
Output required:
==>[Node2:7003,relation1:200166,Node1:22000,Node3:167, Relation5: 11000]
As Node1 is common in both selections, the output must contain all the nodes which are in at least one selection combination without duplicates.
I want to extend this query for multiple selections too including the whole graph. Tried using union
but it didn't work.
If possible also suggest a query to return actual data for the selections.
addV
andaddE
steps that create a sample graph of the structure that represents the one in the photo but perhaps a bit more complex.