Inserting data with graph API

Inserting data with graph API.

The Graph API can be used to insert data into DSE Graph.

Procedure

  1. Add a vertex:
    graph.addVertex(label, 'person', 'personId', 1, 'name','Julia Child', 'gender', 'F')
    The literal label followed by the vertex label are the first two items in the statement, followed by key and value pairs for any properties that are added.
  2. To add an edge using only the graph API, the two vertices that are connected by the edge must be assigned variables that can be used in the addEdge statement:
    juliaChild = graph.addVertex(label, 'person', 'personId', 1, 'name','Julia Child', 'gender', 'F')
    artOfFrenchCookingVolOne = graph.addVertex(label, 'book', 'bookId', 1001, 'name', 'The Art of French Cooking, Vol. 1', 'publishYear', 1961)
    juliaChild.addEdge('authored', artOfFrenchCookingVolOne)
    The outgoing vertex, juliaChild, is connected to the incoming vertex, artOfFrenchCookingVolOne, to create and authored edge.
    If the edge has properties, the key and value pairs are appended in the addEdge statement, similar to the addVertex statement:
    beefBourguignon.addEdge('includedIn', beef, 'amount', '2 lbs')
  3. A property can also be added to a previously created vertex, like jamieOliver:
    jamieOliver.property('gender', 'M', 'nickname', 'jimmy')
  4. To add geospatial data:
    graph.addVertex(label, 'location', 'name', 'Paris', 'point', Geo.point(2.352222, 48.856614))
    graph.addVertex(label, 'lineLocation', 'name', 'ParisLondon', 'line', "LINESTRING(2.352222 48.856614, -0.127758 51.507351)")
    graph.addVertex(label, 'polyLocation','name', 'ParisLondonDublin', 'polygon',Geo.polygon(2.352222, 48.856614, -0.127758, 51.507351, -6.26031, 53.349805))
    A vertex label is created for location that has a point property. A vertex label is created for lineLocation that has a LineString property. A vertex label is created for polyLocation that has a Polygon property.
    Note: For all geospatial elements, the withGeoBounds() method limits searches to a default valid range of latitude in degrees from -90 to +90 (South Pole to North Pole) and a valid range of longitude in degrees from -180 to +180 (east to west from the Greenwich Meridian). The point is specified using Geo.point(longitude, latitude) when adding points, using WellKnownText (WKT) format. Note that is specifies longitude first, then latitude.