title: How to perform cross join on different vertices in Gremlin/Tinkerpop
body: <p>I am new in the graph database. It might be a very basic question but any help is really appreciated.
  I am using Gremlin/Tinkerpop 3 to query a graph stored in TitanDB.</p>
  
  <p>Following is my data set.</p>
  
  <pre><code>User            |  associated_ids
  ---------------------------------
      A           | [ 1, 2 ]
      B           | [ 3, 4 ]
      c           | [ 5 ]
      D           | [ 4, 2 ]
  </code></pre>
  
  <p>Now want to get all the user's group who are linked with each other with any of the associated_id.
  Here [A] &amp; [D] is directly linked as both have common entity [2] and [B] &amp; [D] is directly linked as both have common entity [4].
  So indirectly [A], [B] &amp; [D] are linked.</p>
  
  <p><strong>Expected result something like.</strong></p>
  
  <pre><code>    Users       |  associated_ids
      ----------------------------
      A,B,D       | [ 1, 2 ,3, 4]
      c           | [ 5 ]
  </code></pre>
  
  <p>Following are the steps I have performed to generate the graph.</p>
  
  <pre><code>    a = graph.addVertex(label, "person", "user", "A")
      b = graph.addVertex(label, "person", "user", "B")
      c = graph.addVertex(label, "person", "user", "C")
      d = graph.addVertex(label, "person", "user", "D")
  
      one = graph.addVertex('rec_id')
      one.property('ids', '1')
  
      two = graph.addVertex('rec_id')
      two.property('ids', '2')
  
      three = graph.addVertex('rec_id')
      three.property('ids', '3')
  
      four = graph.addVertex('rec_id')
      four.property('ids', '4')
  
      five = graph.addVertex('rec_id')
      five.property('ids', '5')
  
      a.addEdge('part_of',one)
      a.addEdge('part_of',two)
      b.addEdge('part_of', three)
      b.addEdge('part_of',four)
      c.addEdge('part_of',five)
      d.addEdge('part_of',four)
      d.addEdge('part_of',two)
  </code></pre>
  
  <p><strong>Now wanted to know how can I get all the users who are associated with each other via any of the <code>rec_id</code>.</strong></p>
  
  <p><strong>What would be the Gremlin query to get the desired output?</strong></p>
  
  <p>Also please let me know if I need to do any change in my graph structure to meet my requirement.</p>