Node identifiers in neo4j

I'm new to Neo4j - I started playing with him yesterday.

I noticed that all nodes are identified using the automatically increasing integer that is generated when the node is created - is this always the case?

My dataset has natural string keys, so I would like to avoid matching the Neo4j identity with my own. Can I use string identifiers instead?

+50
neo4j
Jan 29 '12 at 6:38
source share
5 answers

Recall node -id as an implementation detail (for example, the rowid of relational databases can be used to identify nodes, but you should not rely on never reusing them).

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

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 

With an automatic indexer, you would enable automatic 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(); 

See: http://docs.neo4j.org/chunked/milestone/auto-indexing.html And: http://docs.neo4j.org/chunked/milestone/indexing.html

+64
Jan 29 2018-12-12T00:
source share

You can set unique identifiers for nodes / realtionships in Neo4J . You can set its indexing by setting it to one of the configuration files.

In addition, it is highly recommended, for example, to come up with a β€œnatural” identifier for your nodes and edges instead of using the Neo4j seq id. This will save you a round trip in line. This is what I have done in the past.

+1
Jul 13. '16 at 7:42
source share

This should help:

Create an index for automatic indexing during batch import. that if automatic indexing is included in neo4j.properties, each node that will be created will be added to the index named node_auto_index. Now, that's cool. If we add the original index manually (at the time of batch import) and name it as node_auto_index and enable auto indexing in neo4j, then the nodes inserted into the package will appear as if they were auto-indexed. And from there, every time you create a node, the node will also be indexed. **

Source: Identify Nodes Using Custom Keys

0
Oct 10 '14 at 9:02
source share

According to Neo docs, automatic indexes must be installed http://neo4j.com/docs/stable/query-schema-index.html but there are still many limitations

0
Feb 19 '15 at 15:51
source share

In addition to all the answers, neo4j also creates its own identifiers to work faster and better. Make sure that the internal system does not conflict between ids, then it will create nodes with the same properties and show empty nodes in the system.

0
Sep 29 '15 at 17:08
source share



All Articles