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

查看:25
本文介绍了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天全站免登陆