title: How to filter results by node label in neo4j cypher?
body: <p>I have a graph database that maps out connections between buildings and bus stations, where the graph contains other connecting pieces like roads and intersections (among many node types).</p>
  
  <p>What I'm trying to figure out is how to filter a path down to only return specific node types. I have two related questions that I'm currently struggling with.</p>
  
  <p><strong>Question 1: How do I return the labels of nodes along a path?</strong></p>
  
  <p>It seems like a logical first step is to determine what <em>type</em> of nodes occur along the path.</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>MATCH p=(a:Building)­-[:CONNECTED_TO*..5]­-(b:Bus) 
  WITH nodes(p) AS nodes 
  RETURN DISTINCT labels(nodes);
  </code></pre>
  
  <p>However, I'm getting a type exception error that labels() expects data of type node and not Collection. I'd like to dynamically know what types of nodes are on my paths so that I can eventually filter my paths.</p>
  
  <p><strong>Question 2: How can I return a subset of the nodes in a path that match a label I identified in the first step?</strong></p>
  
  <p>Say I found that that between <code>(a:Building)</code> and <code>(d1:Bus)</code> and <code>(d2:Bus)</code> I can expect to find <code>(:Intersection)</code> nodes and <code>(:Street)</code> nodes.</p>
  
  <p>This is a simplified model of my graph:</p>
  
  <pre><code>(a:Building)­­--(:Street)­--­(:Street)--­­(b1:Bus) 
               \­­(:Street)--­­(:Intersection)­­--(:Street)--­­(b2:Bus)
  </code></pre>
  
  <p>I've written a <code>MATCH</code> statement that would look for all possible paths between <code>(:Building)</code> and <code>(:Bus)</code> nodes. What would I need to do next to filter to selectively return the Street nodes?</p>
  
  <pre><code>MATCH p=(a:Building)-[r:CONNECTED_TO*]-(b:Bus)
    // Insert logic to only return (:Street) nodes from p
  </code></pre>
  
  <p>Any guidance on this would be greatly appreciated!</p>