Neo4j:一步一步创建自动索引 [英] Neo4j: Step by Step to create an automatic index

查看:32
本文介绍了Neo4j:一步一步创建自动索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个新的 Neo4j 数据库.我有一种名为 User 的节点,我想要一个关于用户 IdentifierEmailAddress 属性的索引.当数据库是新的时,如何设置索引?我注意到在 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:一步一步创建自动索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆