0

I want to set my own id to the node I create using opencypher I am using below query

CREATE (n:person {ID:'myid', id: 'abc',name:'abcname'})

it created below row

{'~id': '7638bbd4-900d-4b15-b451-5eb848a3db19', '~entityType': 'node', '~labels': ['person'], '~properties': {'ID': 'myid', 'id': 'abc', 'name': 'abcname'}}

but instead I want it to create as below

{'~id': 'myid', '~entityType': 'node', '~labels': ['person'], '~properties': {'name': 'abcname'}}

Please help.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Jigar Gajjar
  • 183
  • 2
  • 12

2 Answers2

2

Since 1.2.0.2 (Nov 22), Neptune supports custom id properties (~id ) in openCypher statements, including CREATE, MERGE, MATCH:

CREATE (n {`~id`: 'fromNode', name: 'john'})
  -[:knows {`~id`: 'john-knows->jim', since: 2020}]
  ->(m {`~id`: 'toNode', name: 'jim'})

MATCH (n {`~id`: 'id1'})
RETURN n

MATCH (n {name: 'john'}), (m {name: 'jim'})
MERGE (n)-[r {`~id`: 'john->jim'}]->(m)
RETURN r

Documentation

Announcement

varontron
  • 1,120
  • 7
  • 21
1

The openCypher specification does not allow for specifying the ~id value for a node, so there is not a way to do this in Neptune currently. Neptune does support setting this value using Gremlin:

g.addV('person').property(T.id, 'myid').property('id', 'abc').property('name', 'abcname')

Which can then be queried using openCypher:

MATCH (n) WHERE id(n)='myid' RETURN n

Updated 7/5/2023:

The answer provided by @varontron is the preferred answer. As they stated, setting the ID value is now supported as of 1.2.0.2 version of Neptune.

bechbd
  • 6,206
  • 3
  • 28
  • 47
  • I see that various drive behaves differently . I am trying CypherGremlinClient.submit("MATCH p=(n)-[r]->(d) WHERE ID(n) = '" + wgiId + "' RETURN n,r") which gives me all details i need but it is very slow. another way or running query very fast but it does not return all attributes. Driver.session.beginTransaction().run("MATCH p=(n)-[r]->(d) WHERE ID(n) = '" + wgiId + "' RETURN n,r") does not give me all attributes, like ~label and ~id – Jigar Gajjar Mar 09 '22 at 01:42
  • With Neptune, you can use Gremlin and openCypher interchangeably on the same data. Due to the limitations of the openCypher spec discussed above, you can specify the `id` value with a Gremlin query but still use openCypher to perform the read queries, which will provide you the information you are requesting. I would steer away from using the translation of the driver. – bechbd Mar 09 '22 at 02:18