Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:24:08+00:00 2026-06-16T22:24:08+00:00

I would like to find a subgraph in Neo4j DB with only strong two

  • 0

I would like to find a subgraph in Neo4j DB with only strong two way relationships.

Let’s say the relationship is LOVES and attribute is Kisses then I would like to only find a subgraph where both sides have kissed the other more than 2 times.

START n=node(*)
MATCH n-[r1:LOVES]->friend<-[r2:LOVES]-n
WHERE r1.Kisses > 2 and r2.Kisses > 2
RETURN n, friend, r1, r2
LIMIT 20

the problem is that the query seems to run forever on a 3M node 30M relationship graph, on a 32GB RAM, quad core system with 16GB max heap for neo4j(neo4j calculator suggested 8GB).

I suspect, there is an endless loop hiding somewhere.

OS: Ubuntu 12.04.1 LTS server

Soft: neo4j-community-1.8.1

java version “1.7.0_10” (neo4j start says to use JDK6)

Java(TM) SE Runtime Environment (build 1.7.0_10-b18)

Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

EDIT: match is incorrect it should be

MATCH n-[r1:LOVES]->friend-[r2:LOVES]->n

UPDATE:
After correcting semantics above, I am still unable to get a full result in 5 minutes.

LOVES is the only relationship type and about 10-20% or relationships have a corresponding one going the other way.

My ultimate goal is to find appropriate Kiss values so that I am left with <100k nodes (and all appropriate LOVES relationships) and can export this subgraph.

Here’s pseudocode for algorithm for what I am trying to do:

let E be edge.list to be processed
let myedgelist be empty list
for e in E:
  if e.n1 > e.n2: # so we do not look twice
    continue
  if not exist(e[n2][n1]): # this is where lookup can be a problem O(1) for hash, O(logn) for sorted, O(n) for something random)
    continue
  if e.kisses > 2 and e[n2][n1].kisses > 2:
    add e to myedgelist
    add e[n2][n1] to myedgelist
return myedgelist

This algorithm should run at most edgecount * log(edgecount), unless there is no effective way to lookup existence of reverse relationship in neo4j, which would seem rather inconceivable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:24:10+00:00Added an answer on June 16, 2026 at 10:24 pm

    Can you try to make friend the target node

    START friend=node(*)
    MATCH n-[r1:LOVES]->friend-[r2:LOVES]->n
    WHERE r1.Kisses > 2 and r2.Kisses > 2
    RETURN n, friend, r1, r2
    LIMIT 20
    

    you can try to split the match into two parts

    START n=node(*)
    MATCH n-[r1:LOVES]->friend
    WHERE r1.Kisses > 2
    WITH n,r1,friend
    MATCH n<-[r2:LOVES]-friend
    WHERE r2.Kisses > 2
    RETURN n, friend, r1, r2
    LIMIT 20
    

    or alternatively only do half of the query with a match and the second half with a filter

    START n=node(*) 
    MATCH n-[r1:LOVES]->friend 
    WHERE r1.Kisses > 2 
     AND ALL(r2 in extract(
                  p in friend-[:LOVES]->n : head(rels(p))) 
             WHERE r2.Kisses > 2) 
    RETURN n, friend, r1
    LIMIT 20
    

    here’s a console to try the queries: http://console.neo4j.org/r/tqvb1p

    But after all you’re processing 3M nodes with a match that potentially blows up to 3M^2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to find a way to store multiple addresses for one subject
I would like to find a way to see what happens while my XAML
I would like to find a way to compile and package our iPhone application
I would like to find a way to use custom User provider within a
I would like to find a way for the possible products of the given
I would like to find the location of a character in a string. Say:
I would like to find a way to explore Array objects in the chrome
I would like to find a good way of identifying names of people, places,
I would like to find a way to get my terminal to give audio
I would like to find an interaction in Javascript that only a human can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.