cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Node properties - Difference between "identity" and "elementId"

Hi, can you please explain the difference between internal properties of a Node "identity" and "elementId"?

I've started to play around with simple Graphs and notices that values of these properties are always identical.

 

{
  "identity": 0, // <-
  "labels": [
    "Person"
  ],
  "properties": {
    "name": "Alice"
  },
  "elementId": "0" // <-
}

Same with the properties of the relationships. Fields "start" and "end" always hold the same values as "startNodeElementId" and "endNodeElementId".

Are there any cases when their values might differ, and is there any semantical distinction between them?

Thanks

1 ACCEPTED SOLUTION

Yes, you are correct that elementid() will replace id(). If you are using V5, then ignore the id property and id() function since is is deprecated. 

View solution in original post

6 REPLIES 6

identity is an internal ID that is unique for every node and relationship in the graph. You can only retrieve this value with the id() function. Keep in mind that identity property values are reused so it is not a good idea to use them to identify a node or property unless you are ABSOLUTELY sure that the node or relationship will never be deleted.

I have no clue what the elementId is. What version Neo4j are you using? Our sandboxes used for our courses use V4.x of Neo4j.

Hi. The release version I'm using is 5.2.0, and I'm running quires in the Neo4j Browser.

Here's a couple of dummy queries creating a node and relationships (please don't judge the second query I understand that it generates a Cartesian product each Foo to all Bar, it's only for demonstration). "elementId", "startNodeElementId" and "endNodeElementId" fields are highlighted.

SimpleNode.pngSimpleRelationship.png

Current documentation says that id() function you've mentioned is deprecated and there's another function with a similar description elementId() "returns a node or relationship identifier, unique within a specific transaction and DBMS".

>> Keep in mind that identity property values are reused so it is not a good idea to use them to identify a node or property unless you are ABSOLUTELY sure that the node or relationship will never be deleted.

That's a very good point.

Yes, you are correct that elementid() will replace id(). If you are using V5, then ignore the id property and id() function since is is deprecated. 

Can someone explain the driver for introducing a new function that seems to do the same thing?  Or, there is some difference between the two values.

The id() function uniquely names a node or relationship ID for a database.

The elementID() uniquely names a node or relationship ID for a DBMS (multiple databases) which is why id() is deprecated. elementID() is more useful in mult-database txns.

So it is unique across all databases, instead of within each database. That makes sense.

Thanks for taking the time to follow up.