cancel
Showing results for 
Search instead for 
Did you mean: 

queries cross graphs

amina
Node Link

Hello,

I'm using a composite database KB that includes two graphs KB.actors and KB.searches

I need to get information about actors that are in KB.actors graph using ids of actors that are the result of a filtre on KB.searches.

I tried this query:

USE KB.searches
MATCH(n:Company) WHERE ...
WITH n.entityId as companyId
USE KB.actors
MATCH(n:Company)-[:ALIAS]->(a:Alias)
WHERE n.entityId=companyId
RETURN companyId, a.term

The query doesn't work "

USE can only appear at the beginning of a (sub-)query
"USE geotrend.actors

Is there any way to join data cross a composite database graphs? is it possible to do it?

Thanks,


1 ACCEPTED SOLUTION

amina
Node Link

Hi,

Thank you for your answers @steve and @glilienfield

Finally the following query worked (inspired from your answers 🙂 ) :


//Query cross databases
CALL{
    use KB.searches
    match(n:Company)
    RETURN n.entityId as id
    LIMIT 200
}
WITH id 
CALL{
    WITH id
    use KB.actors
    MATCH(m:Company)-[:ALIAS]->(a:Alias)
    WHERE m.entityId=id
    RETURN m,a
}
RETURN m.entityId,a.term  

View solution in original post

3 REPLIES 3

glilienfield
Ninja
Ninja

Look into neo4j fabric. It’s only available with enterprise edition. I also looks like neo4j 5.0 improved on its usage.

https://www.markhneedham.com/blog/2020/02/03/neo4j-cross-database-querying-fabric/

steggy
Neo4j
Neo4j

Hi @amina - given that you used the word "composite" database - sounds like you're already using v5? At any rate, I reached out internally, and got this:


They need to wrap the parts that access the dbs as subqueries. A couple of doc links and an example:

https://neo4j.com/docs/operations-manual/current/composite-databases/queries/
https://neo4j.com/docs/cypher-manual/5/clauses/use/#query-use-syntax-composite

https://neo4j.com/docs/operations-manual/current/tutorial/tutorial-composite-database/

CALL  {
  USE KB.searches
  MATCH(n:Company) WHERE ...
  WITH n.entityId as companyId
  RETURN companyId
}
CALL {
  USE KB.actors
  MATCH(n:Company)-[:ALIAS]->(a:Alias)
  WHERE n.entityId=companyId
  RETURN a
}
RETURN companyId, a.term

amina
Node Link

Hi,

Thank you for your answers @steve and @glilienfield

Finally the following query worked (inspired from your answers 🙂 ) :


//Query cross databases
CALL{
    use KB.searches
    match(n:Company)
    RETURN n.entityId as id
    LIMIT 200
}
WITH id 
CALL{
    WITH id
    use KB.actors
    MATCH(m:Company)-[:ALIAS]->(a:Alias)
    WHERE m.entityId=id
    RETURN m,a
}
RETURN m.entityId,a.term  

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online