Inserting data with graph API
Inserting data with graph API.
The Graph API can be used to insert data into DSE Graph.
Procedure
-
Add a vertex:
The literalgraph.addVertex(label, 'person', 'personId', 1, 'name','Julia Child', 'gender', 'F')
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. -
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:
The outgoing vertex, juliaChild, is connected to the incoming vertex, artOfFrenchCookingVolOne, to create andjuliaChild = 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)
authored
edge.If the edge has properties, the key and value pairs are appended in theaddEdge
statement, similar to theaddVertex
statement:beefBourguignon.addEdge('includedIn', beef, 'amount', '2 lbs')
-
A property can also be added to a previously created vertex, like
jamieOliver
:jamieOliver.property('gender', 'M', 'nickname', 'jimmy')
-
To add geospatial data:
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.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))
Note: For all geospatial elements, thewithGeoBounds()
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 usingGeo.point(longitude, latitude)
when adding points, using WellKnownText (WKT) format. Note that is specifies longitude first, then latitude.