How to define schema when using Neptune Client AWS javascript sdk?

0

Hi Everyone, I really need your help in order to define the schema (Nodes, edges, properties and attribute) in my javascript codebase using gremlin or neptune client as I am really not getting a concrete idea of how to define since the data would be dynamic. Please help!

Currently I have defined the nodes as mentioned in below manner but i don't know if it is even correct or not and if it is correct then how to proceed further with relationships and its properties, attribute etcNodes and edges

const gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

async function createNeptuneSchema() {
  const ClusterEndpoint = process.env.CLUSTER_ENDPOINT;
  const Port = 8182;

  const dc = new DriverRemoteConnection(`wss://${ClusterEndpoint}:${Port}/gremlin`, {});
  const g = new gremlin.structure.Graph().traversal().withRemote(dc);

  // Define vertex labels and properties
  await g.addV('Person').property('gender', 'string').property('dob', 'string').next();
  await g.addV('Director').property('title', 'string').next();
  await g.addV('Shareholder').property('snippet', 'string').next();
  await g.addV('Beneficial Owner').property('publishDate', 'string').next();
  await g.addV('Owner').property('content', 'string').next();
  await g.addV('Link').property('source', 'string').next();
  await g.addV('Search Engine Result').property('name', 'string').next();
  await g.addV('Adverse a').property('registrationDate', 'string').next();
  await g.addV('Website').property('updatedDate', 'string').next();
  await g.addV('News').property('lat', 'string').property('lng', 'string').next();
  await g.addV('Domain').property('status', 'string').next();
  await g.addV('Country').property('line1', 'string').property('line2', 'string').property('town', 'string').property('postcode', 'string').next();
  await g.addV('Company').property('offence', 'string').property('enforcementAgency', 'string').property('enforcementType', 'string').next();
  await g.addV('Location').property('politicalPosition', 'string').next();
  await g.addV('Address').property('designationAct', 'string').property('issuingAuthority', 'string').next();
  await g.addV('Fitness Probity').property('otherInfo', 'string').next();
  await g.addV('PEP Record').property('type', 'string').property('value', 'string').next();
  await g.addV('Sanction').property('countryCode', 'string').property('number', 'string').next();
  await g.addV('Search Node').property('platform', 'string').property('username', 'string').next();
  await g.addV('Email').property('category', 'string').next();
  await g.addV('Phone').property('number', 'string').next();
  await g.addV('Alias Name').property('otherInfo', 'string').next();
  await g.addV('Social Profile').property('username', 'string').next();
  await g.addV('Username').property('platform', 'string').next();
  await g.addV('Facebook').property('category', 'string').next();
  await g.addV('Twitter').property('category', 'string').next();
  await g.addV('Education Institute').property('type', 'string').next();
  await g.addV('Risk').property('value', 'string').next();
  await g.addV('Extra').next();
  await g.addV('Notes').next();

  // Define edge label and property


  console.log('Schema creation complete.');
  dc.close();
}

module.exports = createNeptuneSchema;

Dev
asked 2 months ago189 views
1 Answer
0
Accepted Answer

One thing to note is that you're not currently leveraging user-defined IDs. If you have some aspect of your data that is unique across all vertices/edges, the it is best to attempt to use that as a user-defined ID. It will make doing a vertex lookup easier, later on. You can define a user-defined ID by importing id from the t library:

const { t: { id } } = gremlin.process;

and creating an id property as follows:

await g.addV('Person').property(id, 'personid-1234567').property('gender', 'string').property('dob', 'string').next();

Whether you use a user-generated ID or a Neptune-generated ID, you'll need these IDs to create your edges:

await g.addE('knows').from(V('person-123456')).to(V('person-654321')).property('since','2023-01-02').next();

You can also build up relationships in the same query as when defining your vertices through the use of query labels:

await g.addV('Person').property(id, 'personid-1234567').property('gender', 'string').property('dob', 'string').as('a').
    addV('Person').property(id, 'personid-654321').property('gender', 'string').property('dob', 'string').as('b').
    addE('knows').from('a').to('b').property('since','2023-01-02').next();

Here's a good resource for learning how to use Gremlin: https://www.kelvinlawrence.net/book/PracticalGremlin.html

profile pictureAWS
answered 2 months ago
  • Thank you so much for your response Taylor

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions