Working with indexes in neo4j and py2neo -


i have started working py2neo , neo4j.

i confused how go using indices in database.

i have created create_user function:

g = neo4j.graphdatabaseservice() users_index = g.get_or_create_index(neo4j.node, "users") def create_user(name, username, **kwargs):     batch = neo4j.writebatch(g)     user = batch.create(node({"name" : name, "username" : username}))     key, value in kwargs.iteritems():         batch.set_property(user, key, value)     batch.add_labels(user, "user")     batch.get_or_add_to_index(neo4j.node, users_index, "username", username, user)     results = batch.submit()     print "created: " + username 

now obtain users username:

def lookup_user(username):     print node(users_index.get("username", username)[0]) 

i saw schema class , noticed can create index on "user" label, couldn't figure out how obtain index , add entities it.

i want efficient possible, adding index on "user" label add performance, in case add more nodes different labels later on? efficient can be?

also, if want username system unique per user, how able that? how know whether batch.get_or_add_to_index getting or adding entity?

your confusion understandable. there 2 types of indexes in neo4j - legacy indexes (which access get_or_create_index method) , new indexes (which deal indexing based on labels).

the new indexes not need manually kept date, keep in sync make changes graph, , automatically used when issue cypher queries against label/property pair.

the reason legacy indexes kept around support complex functionality not yet available new indexes - such geospatial indexing, full text indexing , composite indexing.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -