I don't think this approach scales, even in an environment that supports recursive queries like PostgreSQL.
The more scalable approach would be to use either a commercial database systems with explicit support for pattern matching or encode conversion path as a string (ex: "top page -> product page with SKU=1337 -> Purchase" becomes "T_SKU1337_P") and use REGEX/GROUP BY.
In all cases, this sounds like a suboptimal use case for either Solr or Elasticsearch.