AT

Gremlin console vs REST API

DCDragos Ciupureanu11/3/2023
I'm trying to get a path and the properties of the vertices and the edges for that path by running a gremlin script via REST API in Neptune. The query is simple with some filters on the edges, but the result is different from what gremlin console gives me. For example, the following query returns the path with the type of entities (vertex or edge) but only the label and the ID properties.
g.V('efc912d3-6cec-49e2-9717-85625bab5243').inE().outV().path()
g.V('efc912d3-6cec-49e2-9717-85625bab5243').inE().outV().path()
Similarly, by adding a by(valueMap()) modulator I get all the properties of all edges and vertices in the path, but not the types ("@type": "g:Edge" and "@type": "g:Vertex") The call to Neptune is done as described here https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-rest.html I guess the question is: is there a way to get the type of entity and all properties with one single query?
Solution:
Generally speaking, the GLVs and the Gremlin Console (if sending queries as bytecode and connecting via websockets) will serialize the results back into types that are common to the runtime that you're using for your application.
Queries sent over HTTP will return the response using GraphSON (GraphSONv3, be default with Neptune) which includes all of the extra type information....
Jump to solution
Solution
Ttriggan11/3/2023
Generally speaking, the GLVs and the Gremlin Console (if sending queries as bytecode and connecting via websockets) will serialize the results back into types that are common to the runtime that you're using for your application.
Queries sent over HTTP will return the response using GraphSON (GraphSONv3, be default with Neptune) which includes all of the extra type information.
DCDragos Ciupureanu11/3/2023
I see, thanks for the clarification. Regarding Neptune and GraphSON though, is there a standard way of getting the same response back in graphson format? I see in the docs that TinkerGraph has a different serializer than the rest. For more context here, I'm trying to build a simple UI that shows a very basic subraph to our users. I am using gdotv myself, but that's local and not a good solution for users - and I'm looking for something generic that given any arbitrary query I can construct and vizualize a graph. Is this a matter of me parsing the query before sending it to Neptune and change it to return a path and then ask for the same traversal but with a valueMap in the by modulator?
Sspmallette11/3/2023
Note that properties will (can) be returned on elements after 3.7.0: https://tinkerpop.apache.org/docs/current/upgrade/#_properties_on_elements Neptune does not yet support that version but should relatively soon.
Ttriggan11/3/2023
@Dragos Ciupureanu - which client are you using to interact with Neptune?
DCDragos Ciupureanu11/3/2023
I'm doing a simple POST request to Neptune's REST API from Javascript right now
Ttriggan11/3/2023
Another approach... we now have support for issuing queries via the AWS CLI and SDKs. Still requires network access to your cluster endpoints. Example here:
const { NeptunedataClient, ExecuteGremlinQueryCommand } = require( "@aws-sdk/client-neptunedata" );

( main = async () => {
const config = {
endpoint: "https://neptunedbcluster-abcdefghij.cluster-abcdefghij.us-west-2.neptune.amazonaws.com:8182",
region: "us-west-2",
};
const client = new NeptunedataClient(config);
const input = {
gremlinQuery: "g.V(['1','2']).as('a').mergeE([(T.label): 'likes',(from): '3',(to): Merge.inV]).option(Merge.inV, select('a')).elementMap()",
serializer: "application/vnd.gremlin-v1.0+json;types=false",
}
const command = new ExecuteGremlinQueryCommand(input);

try {
const results = await client.send(command);
console.log(JSON.stringify(results.result.data));
} catch (err) {
console.error(err);
}
})
main();
const { NeptunedataClient, ExecuteGremlinQueryCommand } = require( "@aws-sdk/client-neptunedata" );

( main = async () => {
const config = {
endpoint: "https://neptunedbcluster-abcdefghij.cluster-abcdefghij.us-west-2.neptune.amazonaws.com:8182",
region: "us-west-2",
};
const client = new NeptunedataClient(config);
const input = {
gremlinQuery: "g.V(['1','2']).as('a').mergeE([(T.label): 'likes',(from): '3',(to): Merge.inV]).option(Merge.inV, select('a')).elementMap()",
serializer: "application/vnd.gremlin-v1.0+json;types=false",
}
const command = new ExecuteGremlinQueryCommand(input);

try {
const results = await client.send(command);
console.log(JSON.stringify(results.result.data));
} catch (err) {
console.error(err);
}
})
main();
Using the serializer above, it returns data in the more concise format without types:
[
{
"id": "c4c5cb1e-ba3a-5be9-4717-536eef3b4de9",
"label": "likes",
"IN": {
"id": "1",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
},
{
"id": "1ec5cb1e-ba3a-3636-b15e-e5d1e999da7c",
"label": "likes",
"IN": {
"id": "2",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
}
]
[
{
"id": "c4c5cb1e-ba3a-5be9-4717-536eef3b4de9",
"label": "likes",
"IN": {
"id": "1",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
},
{
"id": "1ec5cb1e-ba3a-3636-b15e-e5d1e999da7c",
"label": "likes",
"IN": {
"id": "2",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
}
]
More info on this Javascript module here: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-neptunedata/
DCDragos Ciupureanu11/6/2023
This is great, thanks for the suggestion.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Cryptic Neptune Gremlin Error Rate Creeping - What Would You Recommend?This relates more to do with Neptune usage, nevertheless, it is also related to the Gremlin Query erkubehoundIf anyone is familiar with KubeHound DSL. Can someone explain why Query 1 is different from Query 2.Help with visualizing in the graph-notebookI am trying to visualize a graph in the graph-notebook but no matter what I do I cannot get it to beGremlin browser code editorHi, I'm looking for a code editor like monaco https://microsoft.github.io/monaco-editor/ to embed inConnecting to local gremlin server with websocket addressHello everyone. I'm looking for help with a client app written in Java that uses Tinkerpop Gremlin tClarification on Kerberos configuration for Gremlin DriverI'm a little bit unclear on the role of the JAAS configuration file for the Gremlin client in the coGremlin Driver and frequently changing serversIn a containerised environment, hosts are frequently replaced and their IP address can change severaGlobal SearchIs there a way where i can scan all the vertex or edge properties that match a given keyword in gremGraphSON mapperHi, I'm trying to ingest some data into AWS Neptune and due to its size I'm forced to use a bulk d.drop() behavior confussionI have a basic java app and I'm learning hot to send gremlin queries to a JanusGraph from that java Can I name the result of an anonymous traversal without moving the traverser?I can currently do the following: ``` Graph graph = TinkerFactory.createModern(); GraphTraversalSCan GraphBinary be used to save a graph to file?Can GraphBinary be used to save graph in a file. Any example is welcome.How to get cardinality of property?I have a multi property and I want to find out its cardinality. How can I do that? valueMap/elementMinverted regex searchHey, In my vertices I store escaped regexp statements as labels (e.g: 'wh.' which in theory should Debug message spam from tinkerpop server 3.7Right now, when connecting to my local tinkerpop server, I am getting incredible amounts of debug loShould by() Modulator Work For More Types?This works. `gremlin> g.V().out().out().path().by("name") ==>[marko,josh,ripple] ==>[marko,josh,lop]InProcess GraphDB with Gremlin Support? (C# or NodeJS)Hello, is there any in process GraphDB out there in the world? Best would be c# or NodeJS and not JaEasiest Way to Get List Cardinality Properties As a List?What is the easiest way to retrieve the vertex properties that have list cardinality back as a list filter lambda in remote consolehi all, i’m trying to do filter on remote console to neptune server but keep getting MalformedQueryEwithin() and case insensitiveI need to check if a property of a node is in a list of values. How can I do that in a case insensit