Sample Neo4j queries
19 May 2016Find nodes that have relationship Is_Executive_Of between:
MATCH (person)-[:Is_Executive_Of]->(n) RETURN person, n
╒══════════════════════════════╤══════════════════════════════╕
│person │n │
╞══════════════════════════════╪══════════════════════════════╡
│{character_wiki_url: Tortoise_│{faction_name: Veracity, facti│
│Camrhyne, character_name: Tort│on_id: 1} │
│oise, character_species: Tyrta│ │
│lian, character_religion: Mari│ │
│ssaism, character_id: 1, chara│ │
│cter_level: 33} │ │
├──────────────────────────────┼──────────────────────────────┤
│{character_wiki_url: Osric_Lio│{faction_name: BrotherhoodofSt│
│san, character_name: Osric, ch│inger, faction_id: 15} │
│aracter_species: Metiate, char│ │
│acter_religion: Justice, chara│ │
│cter_id: 5, character_level: 2│ │
│9_15} │ │
├──────────────────────────────┼──────────────────────────────┤
With python and py2neo:
>>> from py2neo import Graph
>>> graph = Graph('http://neo4j:neo4j@localhost:7474/db/data')
>>> res = graph.cypher.execute('MATCH (person)-[:Is_Executive_Of]->(n) RETURN person, n')
>>> for z in old_person_res:
print dict( z.person.properties, **{'labels': list(z.person.labels)} ), dict( z.n.properties, **{'labels': list(z.n.labels)} )
...
...
{'labels': [u'Character'], u'character_id': u'1', u'character_religion': u'Marissaism', u'character_wiki_url': u'Tortoise_Camrhyne', u'character_level': u'33', u'character_species': u'Tyrtalian', u'character_name': u'Tortoise'} {u'faction_id': u'1', 'labels': [u'Faction'], u'faction_name': u'Veracity'}
{'labels': [u'Character'], u'character_id': u'5', u'character_religion': u'Justice', u'character_wiki_url': u'Osric_Liosan', u'character_level': u'29_15', u'character_species': u'Metiate', u'character_name': u'Osric'} {u'faction_id': u'15', 'labels': [u'Faction'], u'faction_name': u'BrotherhoodofStinger'}