title: Find paths from a graph and then count how many times a path occurs in Azure Cosmos DB using Gremlin
body: <p>I am storing clickstream events in graph database using the below structure
  <a href="https://i.stack.imgur.com/cFrE1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cFrE1.png" alt="enter image description here"></a></p>
  
  <p>User perform multiple events and each event has a edge towards previous event: </p>
  
  <ul>
  <li>Vertices are 'user' and 'event'  </li>
  <li>Edges are 'performed' and 'previous'  </li>
  </ul>
  
  <p>Each event has a property named referer.
  For eg, if a user views a page www.foobar.com/aaa
  then there will be a page view event and it will have referer:www.foobar.com/aaa</p>
  
  <p>Now I want to find the possible paths from homepage with their count</p>
  
  <p>Using the below Gremlin query I am able to find the possible paths, but I am not able to group them to find counts of each path:</p>
  
  <pre><code>g.V().hasLabel('event').has('referer','https://www.foobar.com/').in('previous').in('previous').path().by('referer')
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code> [
        {
          "labels": [
            [],
            [],
            []
          ],
          "objects": [
            "https://www.foobar.com/",
            "https://www.foobar.com/aaa",
            "https://www.foobar.com/bbb"
          ]
        },
        {
          "labels": [
            [],
            [],
            []
          ],
          "objects": [
            "https://www.foobar.com/",
            "https://www.foobar.com/aaa",
            "https://www.foobar.com/bbb"
          ]
        },
        {
          "labels": [
            [],
            [],
            []
          ],
          "objects": [
            "https://www.foobar.com/",
            "https://www.foobar.com/ccc",
            "https://www.foobar.com/ddd"
          ]
        }
      ]
  </code></pre>
  
  <p>I want an output like this:</p>
  
  <pre><code>[[
    "https://www.foobar.com/",
    "https://www.foobar.com/aaa",
    "https://www.foobar.com/bbb"
  ]:2,
  [
    "https://www.foobar.com/",
    "https://www.foobar.com/ccc",
    "https://www.foobar.com/ddd"
  ]:1]
  </code></pre>
  
  <p>Since I am using azure cosmos graph db only these gremlin operators are available
  <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/gremlin-support" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/cosmos-db/gremlin-support</a><br>
  Thanks </p>