Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-11-2023 06:42 PM - edited 01-12-2023 04:53 AM
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
Solved! Go to Solution.
01-12-2023 10:28 AM
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.
01-12-2023 05:10 AM
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.
01-12-2023 09:49 AM - edited 01-12-2023 09:51 AM
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.
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.
01-12-2023 10:28 AM
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.
01-12-2023 11:22 AM
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.
01-12-2023 02:45 PM
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.
01-12-2023 02:50 PM
So it is unique across all databases, instead of within each database. That makes sense.
Thanks for taking the time to follow up.
All the sessions of the conference are now available online