我正在创建一个新的 Neo4j 数据库.我有一种名为 User 的节点,我想要一个关于用户 Identifier 和 EmailAddress 属性的索引.当数据库是新的时,如何设置索引?我注意到在 neo4j.properties 文件中似乎支持创建索引.但是,当我将这些设置为这样时
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;然后我得到一个
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.
推荐答案在neo4j.properties文件中加入以下内容
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为节点创建自动索引
neo4j-sh (0)$ index --create node_auto_index -t Node检查它们是否存在
neo4j-sh (0)$ index --indexes应该回来
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;由于节点是自动索引的,所以索引的名称是node_auto_index
As the node is auto indexed the name of the index is node_auto_index
此信息来自此页面底部的评论
更新
如果您想索引在自动索引打开之前存在的当前数据(其中 Property_Name 是索引的名称)
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);更多推荐
Neo4j:一步一步创建自动索引
发布评论