0

I have been trying to understand the difference between old indexes and current indexing scheme in Neo4j and I have trouble understanding whether I actually need to use graph_db.get_or_create_indexed_node or not. I have an example and I would appreciate if someone could point out what is the difference between 2 approaches.

USING INDEXES:

patients = graph_db.get_or_create_index(neo4j.Node,"patients")
doctors=graph_db.get_or_create_index(neo4j.Node,"doctors")

p1 = graph_db.get_or_create_indexed_node("patients", "p1", "disease1", {"p1":"disease1", "gender" : "F"})

p2 = graph_db.get_or_create_indexed_node("patients", "p2", "disease2", {"p2":"disease2", "gender" : "M"})

p3 = graph_db.get_or_create_indexed_node("patients", "p3", "disease3", {"p3":"disease3", "gender" : "M","return":'yes'})

d1=graph_db.get_or_create_indexed_node("doctors","d1",{"years_experience":"20","re-admission_rate":"20%"})
d2=graph_db.get_or_create_indexed_node("doctors","d2",{"years_experience":"2","re-admission_rate":"40%"})

USING LABELS

patients=[{"patients", "p1", "disease1", {"p1":"disease1", "gender" : "F"}},{"patients", "p2", "disease2", {"p2":"disease2", "gender" : "M"}}]
doctors=[{"doctors","d1",{"years_experience":"20","re-admission_rate":"20%"}}]

for patient in patients:
    t=batch.create(patient)
    batch.add_labels(t,'Patient')
batch.submit()
batch.clear()

Also, if I want to batch add relationships (let's say patient1 visits doctor1 today and in one month), how do I do that? Do I add new relationship with a timestamp as a label?

Anastasia
  • 864
  • 5
  • 13
  • 26
  • 2
    This will help: http://nigelsmall.com/neo4j/index-confusion – FrobberOfBits Oct 29 '14 at 17:36
  • I have read that. However, it will help me greatly if someone could tell me if 2 approaches above are different in the sense of Cypher queries performed on created data and if they are, why. – Anastasia Oct 29 '14 at 17:38
  • For your second question, I'd probably model the "visit" as a node as you then can attach other information to it too. But yes otherwise you'd put a timestamp property on it. – Michael Hunger Oct 30 '14 at 02:30

0 Answers0