How to pass variable dynamically in gremlin (NeptuneDB)

471 views
Skip to first unread message

Minh_Tiến

unread,
Dec 2, 2021, 9:43:10 PM12/2/21
to Gremlin-users
Hi all,
I am using aws neptunedb for my application with java backend. Now I want to pass a dynamic variable in the query to filter the product information.
My query is below:
%%gremlin
g.V().has("product","name","Tshirt").as("A").
    out("is_produced").as("B").
    out("is_located").as("C").
    select("A","B","C").
    by(valueMap("name","price").by(unfold())).
    by(valueMap("producer").by(unfold())).
    by(valueMap("country","state","street).by(unfold()))
I have 1000 goods, So i want to change Tshirt with a flexible variable 'X'  in my query. Can i do that with gremlin for my app. 
Can someone please help me? thanks in advance!

Stephen Mallette

unread,
Dec 7, 2021, 6:57:43 AM12/7/21
to gremli...@googlegroups.com
Your question is a bit confusing because you mention Java but I also see " %%gremlin" syntax. Could you please clarify what you are asking?

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/41f2ebfe-e7cf-4f90-910e-2732343e6c93n%40googlegroups.com.

HARI KISHAN

unread,
Dec 9, 2021, 2:38:47 PM12/9/21
to Gremlin-users
One way to query and visualize AWS Neptune DB is by using Neptune Workbench provided by AWS Sagemaker's Jupyter notebooks.

In the Jupyter notebook, we write %%gremlin to turn the cell to Neptune magic cell. This way, the magic cell will take the gremlin query written after %%gremlin as input and query the Neptune endpoint through WebSocket, and returns the result in the notebook.

Below is the example:
%%gremlin - represents that the below input is the gremlin query that should be executed on Neptune DB through websocket.

The query g.addV('car').property('make','ford').property('model','explorer') when executed returns the ID of the vertex created in console.
Screen Shot 2021-12-09 at 2.01.50 PM.png

Finally, I think you can ignore %%gremlin 

Stephen Mallette

unread,
Dec 13, 2021, 6:51:05 AM12/13/21
to gremli...@googlegroups.com
Neptune doesn't let you send parameters/bindings via scripts:


If you send a bytecode based request, which is preferred, you can declare a variable in your programming language and use it in your Gremlin as you normally would with any programming task.



Reply all
Reply to author
Forward
0 new messages