Yes, you just helped clear up a basic misunderstanding of indexing in
Neo4J on my part. Thanks for the quick reply.
Thanks James for the explanation!
Send from mobile.
Hi,i'm having trouble with exactly this feature.Illustration on the quickstart example:
class Person(Node):element_type = "person"
name = String(nullable=False)age = Integer()class Knows(Relationship):label = "knows"created = DateTime(default=current_datetime, nullable=False)test:print "start"g = Graph()print "before config"#g.config.set_logger(DEBUG)#std examplejames = g.vertices.create(name="James")julie = g.vertices.create(name="Julie")g.edges.create(james, "knows", julie)print "add proxy"g.add_proxy("people", Person)g.add_proxy("knows", Knows)print "add persons"james2 = g.people.create(name="James2")julie2 = g.people.create(name="Julie2")print "add relation"g.knows.create(james2, julie2)g.knows.create(james, julie2)print "result:"print g.Vprint len(list(g.vertices.index.lookup(name="James")))print len(list(g.vertices.index.lookup(name="James2")))
normally the ouptut of the first and second len() statement should be equal. but instead the output is (debug off for readability):startbefore configadd proxyadd personsadd relationresult:[<Vertex: http://localhost:7474/db/data/node/49>, <Vertex: http://localhost:7474/db/data/node/50>, <Person: http://localhost:7474/db/data/node/51>, <Person: http://localhost:7474/db/data/node/52>]10can you point me sth that i am probably doing wrong? system is ubuntu 12.04 64bit and atm i dont have gremmlin standalone installedcheers and regards,benoutput with debug on:startbefore configPOST body: {"params":{"keys":null,"index_name":"vertex","data":{"name":"James"}},"script":"neo4j = g.getRawGraph()\n manager = neo4j.index()\n g.setMaxBufferSize(0)\n g.startTransaction()\n try {\n index = manager.forNodes(index_name)\n vertex = neo4j.createNode()\n for (entry in data.entrySet()) {\n if (entry.value == null) continue;\n vertex.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n\tindex.add(vertex,entry.key,String.valueOf(entry.value))\n }\n g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\n return vertex\n } catch (e) {\n g.stopTransaction(TransactionalGraph.Conclusion.FAILURE) \n return e\n }"}POST body: {"params":{"keys":null,"index_name":"vertex","data":{"name":"Julie"}},"script":"neo4j = g.getRawGraph()\n manager = neo4j.index()\n g.setMaxBufferSize(0)\n g.startTransaction()\n try {\n index = manager.forNodes(index_name)\n vertex = neo4j.createNode()\n for (entry in data.entrySet()) {\n if (entry.value == null) continue;\n vertex.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n\tindex.add(vertex,entry.key,String.valueOf(entry.value))\n }\n g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\n return vertex\n } catch (e) {\n g.stopTransaction(TransactionalGraph.Conclusion.FAILURE) \n return e\n }"}POST body: {"params":{"label_var":"label","outV":53,"keys":null,"data":{},"inV":54,"index_name":"edge","label":"knows"},"script":"import org.neo4j.graphdb.DynamicRelationshipType;\n neo4j = g.getRawGraph()\n manager = neo4j.index()\n vertex = neo4j.getNodeById(outV)\n relationshipType = DynamicRelationshipType.withName(label)\n g.setMaxBufferSize(0)\n g.startTransaction()\n try {\n index = manager.forRelationships(index_name)\n edge = vertex.createRelationshipTo(neo4j.getNodeById(inV),relationshipType)\n for (entry in data.entrySet()) {\n if (entry.value == null) continue;\n edge.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n\tindex.add(edge,entry.key,String.valueOf(entry.value))\n }\n index.add(edge,label_var,String.valueOf(label))\n g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\n return edge\n } catch (e) {\n g.stopTransaction(TransactionalGraph.Conclusion.FAILURE)\n return e\n }"}add proxyGET body: NonePOST url: http://localhost:7474/db/data/index/nodePOST body: {"config":{"type":"exact","provider":"lucene"},"name":"person"}GET body: NonePOST body: {"name":"knows"}add personsPOST body: {"params":{"keys":null,"index_name":"person","data":{"element_type":"person","name":"Jamesxxx"}},"script":"neo4j = g.getRawGraph()\n manager = neo4j.index()\n g.setMaxBufferSize(0)\n g.startTransaction()\n try {\n index = manager.forNodes(index_name)\n vertex = neo4j.createNode()\n for (entry in data.entrySet()) {\n if (entry.value == null) continue;\n vertex.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n\tindex.add(vertex,entry.key,String.valueOf(entry.value))\n }\n g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\n return vertex\n } catch (e) {\n g.stopTransaction(TransactionalGraph.Conclusion.FAILURE) \n return e\n }"}POST body: {"params":{"keys":null,"index_name":"person","data":{"element_type":"person","name":"Julie500"}},"script":"neo4j = g.getRawGraph()\n manager = neo4j.index()\n g.setMaxBufferSize(0)\n g.startTransaction()\n try {\n index = manager.forNodes(index_name)\n vertex = neo4j.createNode()\n for (entry in data.entrySet()) {\n if (entry.value == null) continue;\n vertex.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n\tindex.add(vertex,entry.key,String.valueOf(entry.value))\n }\n g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\n return vertex\n } catch (e) {\n g.stopTransaction(TransactionalGraph.Conclusion.FAILURE) \n return e\n }"}add relationPOST body: {"params":{"label_var":"label","outV":55,"keys":null,"data":{"created":1340659699},"inV":56,"index_name":"knows","label":"knows"},"script":"import org.neo4j.graphdb.DynamicRelationshipType;\n neo4j = g.getRawGraph()\n manager = neo4j.index()\n vertex = neo4j.getNodeById(outV)\n relationshipType = DynamicRelationshipType.withName(label)\n g.setMaxBufferSize(0)\n g.startTransaction()\n try {\n index = manager.forRelationships(index_name)\n edge = vertex.createRelationshipTo(neo4j.getNodeById(inV),relationshipType)\n for (entry in data.entrySet()) {\n if (entry.value == null) continue;\n edge.setProperty(entry.key,entry.value)\n if (keys == null || keys.contains(entry.key))\n\tindex.add(edge,entry.key,String.valueOf(entry.value))\n }\n index.add(edge,label_var,String.valueOf(label))\n g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)\n return edge\n } catch (e) {\n g.stopTransaction(TransactionalGraph.Conclusion.FAILURE)\n return e\n }"}result:POST body: {"params":null,"script":"g.getVertices()"}[<Vertex: http://localhost:7474/db/data/node/53>, <Vertex: http://localhost:7474/db/data/node/54>, <Person: http://localhost:7474/db/data/node/55>, <Person: http://localhost:7474/db/data/node/56>]GET body: None1GET body: None0
print "add persons"james2 = g.people.create(name="James2")julie2 = g.people.create(name="Julie2")print "add relation"g.knows.create(james2, julie2)g.knows.create(james, julie2)print "result:"print g.Vprint len(list(g.vertices.index.lookup(name="James")))print len(list(g.vertices.index.lookup(name="James2")))
Hi Ben -
For example, in your case, james2 is in the person index, and you can look it up like this:>>> g.people.index.lookup(name="James2")- James