neo4j中的节点标识符 [英] Node identifiers in neo4j

查看:142
本文介绍了neo4j中的节点标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Neo4j的新手-昨天晚上才刚开始玩它.

I'm new to Neo4j - just started playing with it yesterday evening.

我注意到所有节点都由在节点创建过程中生成的自动递增的整数来标识-总是这样吗?

I've notice all nodes are identified by an auto-incremented integer that is generated during node creation - is this always the case?

我的数据集具有自然的字符串键,因此我希望避免在Neo4j分配的ID与我自己的ID之间进行映射.可以使用字符串标识符代替吗?

My dataset has natural string keys so I'd like to avoid having to map between the Neo4j assigned ids and my own. Is it possible to use string identifiers instead?

推荐答案

将node-id视为实现细节(就像关系数据库的rowid一样,可以用来标识节点,但永远不要依赖它)重新使用).

Think of the node-id as an implementation detail (like the rowid of relational databases, can be used to identify nodes but should not be relied on to be never reused).

您应将自然键作为属性添加到节点,然后使用自然键索引节点(或为其启用自动索引).​​

You would add your natural keys as properties to the node and then index your nodes with the natural key (or enable auto-indexing for them).

例如Java API中的

E..g in the Java API:

Index<Node> idIndex = db.index().forNodes("identifiers");

Node n = db.createNode();
n.setProperty("id", "my-natural-key");
idIndex.add(n, "id",n.getProperty("id"));

// later
Node n = idIndex.get("id","my-natural-key").getSingle(); // node or null

使用自动索引器,您将为"id"字段启用自动索引.

With auto-indexer you would enable auto-indexing for your "id" field.

// via configuration 
GraphDatabaseService db = new EmbeddedGraphDatabase("path/to/db",
 MapUtils.stringMap( 
    Config.NODE_KEYS_INDEXABLE, "id", Config.NODE_AUTO_INDEXING, "true" ));

// programmatic (not persistent)
db.index().getNodeAutoIndexer().startAutoIndexingProperty( "id" );

// Nodes with property "id" will be automatically indexed at tx-commit
Node n = db.createNode();
n.setProperty("id", "my-natural-key");

// Usage
ReadableIndex<Node> autoIndex = db.index().getNodeAutoIndexer().getAutoIndex();
Node n = autoIndex.get("id","my-natural-key").getSingle();

请参阅: http://docs.neo4j.org/chunked/milestone/auto-indexing.html 并且: http://docs.neo4j.org/chunked/milestone/indexing.html

这篇关于neo4j中的节点标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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