Relationships are not showing in the graph by using neovis.js

cypher
neovis

(Babu Ganesh0708) #1

Hi All,

I am trying to show the top 10 node in the graph and below is the query I tried in neo4j browser,

MATCH (p1:Username)-[r:sent]->(p2:Username) 
RETURN p1, count(*) AS count 
ORDER BY count DESC LIMIT 10

As below image shows the top 10 nodes with their relationship

Similarly I am trying to show the graph using neovis.js and I can able to show the top 10 nodes in the visualization but not sure why the relationships are not showing in the graph.

Below is the response,

neovis javascript function,

function draw() {
            var config = {
                container_id: "viz",
                server_url: "bolt://localhost:7687",
				arrows: true,
                labels: {
                    "Username": {
                        "caption": "mail_id",
						"size": "pagerank",
                        "community": "partition"
                    }
                },
                relationships: {
					"sent": {
                        "thickness": "count",
                        "caption": false
                    }
                },
				initial_cypher: "MATCH (p1:Username)-[r:sent]->(p2:Username) RETURN p1, count(*) AS count ORDER BY count DESC LIMIT 10"
            };

            viz = new NeoVis.default(config);
            viz.render();
        }

Please correct me If am doing anything wrong in the query and let me know your thoughts.

Regards,
Ganeshbabu R


(Michael Hunger) #2

You also have to return the relationships.

e.g.

MATCH (p1:Username)
with p1, size((p1)-[r:sent]->()) as count
order by count desc limit 10
match (p1)-[r]->()
RETURN p1, r


(Babu Ganesh0708) #3

Thanks @michael.hunger

Yes it solved the problem..

Also similar problem I am facing now and we have two nodes (Username & Topics) and I am trying to show the top topics which discussed among the users and below is the query to load the data to neo4j

LOAD CSV WITH HEADERS FROM "file:///data_email.csv" AS row
WITH row WHERE row.message_subject <> 'none' AND row.keywords <> 'none'
MERGE (p1:Username {mail_id: row.sender_address}) ON CREATE SET p1.timestamp = row.date_time 
MERGE (p2:Username {mail_id: row.recipient_address})
MERGE (p3:Topic {topic: row.keywords})
WITH p1, p2, p3, row, COUNT(*) AS count
MERGE (p1)-[r1:sent]->(p2) ON CREATE SET r1.time = row.date_time, r1.count = count
MERGE (p1)-[r2:sender_interest]->(p3)<-[r3:receiver_interest]-(p2) ON CREATE SET r2.sentcount = count, r3.receivecount = count

After I loaded the data to neo4j below is the query I tried to show the top 10 topics with the users in neo4j browser,

MATCH (p1:Username)-[r2:sender_interest]->(t:Topic)
WITH p1, t, count(r2) as count
RETURN p1.mail_id as sender, t.topic as topics, count
ORDER BY count DESC
LIMIT 10

Response of the query,

Now I am trying to show the top 10 topics using neovis.js but don't know why the data is not showing up and I wanted to show the thickness based on the relationship count.

**Below is the neovis javascript function,
**

var config = {
                container_id: "viz",
				server_url: "bolt://localhost:7687",
				arrows: true,
                labels: {
                    "Username": {
                        "caption": "mail_id",
						"size": "pagerank",
                        "community": "partition"
                    },
					"Topic": {
					    "caption": "topic"
					}
                },
                relationships: {
					"sender_interest": {
					    "thickness": "sentcount",
						"caption": false
					}
                },
                initial_cypher: "MATCH (p1:Username),(p3:Topic) with p1, p3, size((p1:Username)-[:senderinterest]-(p3:Topic)) as count order by count desc limit 10 MATCH (p1)-[r:senderinterest]->(p3) RETURN p1, p3, r"
            };

Also I am having less confident of the way I have set the count value for interest relationship.
Please correct me If I am doing anything wrong.

Regards,
Ganeshbabu R


(Michael Hunger) #4

To test it I recommend running these in neo4j browser and work step by step in your query.

Are you actually looking for users that have sent a lot or topics that got a lot
or the same topic and user that had most interactions?
You can simplify this:

MATCH (p1:Username)
with p1, size((p1)-[:senderinterest]->()) as count 
order by count desc limit 10 
MATCH (p1)-[r:senderinterest]->(p3) RETURN p1, p3, r

(Ameyasoft) #5

Hi,

Try this query to get topic and total number of users discussed.

MATCH (t:Topic)-[:sender_interest]-(p)
WITH t, count(distinct p) as Cnt
MATCH (t)-[:receiver_interest]-(q)
WITH t, count(distinct q) + Cnt as Tot
RETURN t.topic, Tot;

Here is the result with your previously published data with one topic:
bganesh3

-Kamal