Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

database - Neo4j: Step by Step to create an automatic index

I am creating a new Neo4j database. I have a type of node called User and I would like an index on the properties of user Identifier and EmailAddress. How does one go setting up an index when the database is new? I have noticed in the neo4j.properties file there looks to be support for creating indexes. However when I set these as so

# Autoindexing

# Enable auto-indexing for nodes, default is false
node_auto_indexing=true

# The node property keys to be auto-indexed, if enabled
node_keys_indexable=EmailAddress,Identifier

And add a node and do a query to find an Identifier that I know exists

START n=node:Identifier(Identifier = "USER0")
RETURN n;

then I get an

MissingIndexException: Index `Identifier` does not exist

How do I create an index and use it in a start query? I only want to use config files and cypher to achieve this. i.e. at the present time I am only playing in the Power Tool Console.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add the following to the neo4j.properties file

# Autoindexing

# Enable auto-indexing for nodes, default is false
node_auto_indexing=true

# The node property keys to be auto-indexed, if enabled
node_keys_indexable=EmailAddress,Identifier

Create the auto index for nodes

neo4j-sh (0)$ index --create node_auto_index -t Node

Check if they exist

neo4j-sh (0)$ index --indexes

Should return

Node indexes:
node_auto_index

When querying use the following syntax to specify the index

start a = node:node_auto_index(Identifier="USER0")
return a;

As the node is auto indexed the name of the index is node_auto_index

This information came from a comment at the bottom of this page

Update

In case you want to index your current data which was there before automatic indexing was turned on (where Property_Name is the name of your index)

START nd =node(*) 
WHERE has(nd.Property_Name)
WITH nd
SET nd.Property_Name = nd.Property_Name
RETURN count(nd);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...