title: TinkerPop: Multi-Level search to multiple - vertex types
body: <p><strong>Sample Graph</strong>: <a href="http://tinkerpop.apache.org/docs/current/images/tinkerpop-modern.png" rel="nofollow noreferrer">Tinker Modern</a></p>
  
  <p><strong>Query</strong>: Find all direct friends (<code>person</code> Vertex) of Marko and (union) all <code>software</code> in second hop.</p>
  
  <hr>
  
  <p><strong>Failed attempts:</strong></p>
  
  <blockquote>
    <p>Generic Query for first level people:</p>
  </blockquote>
  
  <pre><code>g.V(1).hasLabel("person").repeat(both()).times(1).emit(hasLabel("person")).hasLabel("person").values("name")
  </code></pre>
  
  <blockquote>
    <p>Generic Query for second level/hop software:</p>
  </blockquote>
  
  <pre><code>g.V(1).hasLabel("person").repeat(both()).times(2).emit(hasLabel("software")).hasLabel("software").values("name")
  </code></pre>
  
  <blockquote>
    <p>Attempt to merge above two queries:</p>
  </blockquote>
  
  <pre><code>g.V(1).hasLabel("person").repeat(both()).times(1).emit(hasLabel("person")).hasLabel("person").repeat(both()).times(2).emit(hasLabel("software")).hasLabel("software").values("name")
  </code></pre>
  
  <p>I didn't really understand how union works, because its not merging data.</p>
  
  <pre><code>g.V(1).union().V(2)
  g.V(1).union(V(2))
  </code></pre>
  
  <p>Best I got till now is, but I want some ability to do like (marko connected to person AND/OR marko connected to software):</p>
  
  <pre><code>gremlin&gt; g.V(1).store('x').V(2).store('y').cap('x', 'y')
  ==&gt;[x:[v[1]],y:[v[2]]]
  </code></pre>