Skip to content

Latest commit

 

History

History
162 lines (114 loc) · 6.94 KB

quickstart-console.md

File metadata and controls

162 lines (114 loc) · 6.94 KB
title titleSuffix description author ms.author ms.service ms.subservice ms.custom ms.topic ms.date
Quickstart: Traverse vertices & edges with the console
Azure Cosmos DB for Apache Gremlin
In this quickstart, connect to an Azure Cosmos DB for Apache Gremlin account using the console. Then; create vertices, create edges, and traverse them.
manishmsfte
mansha
azure-cosmos-db
apache-gremlin
devx-track-azurecli
quickstart
09/27/2023

Quickstart: Traverse vertices and edges with the Gremlin console and Azure Cosmos DB for Apache Gremlin

[!INCLUDEGremlin]

[!INCLUDEGremlin devlang]

Azure Cosmos DB for Apache Gremlin is a fully managed graph database service implementing the popular Apache Tinkerpop, a graph computing framework using the Gremlin query language. The API for Gremlin gives you a low-friction way to get started using Gremlin with a service that can grow and scale out as much as you need with minimal management.

In this quickstart, you use the Gremlin console to connect to a newly created Azure Cosmos DB for Gremlin account.

Prerequisites

[!INCLUDECloud Shell]

Create an API for Gremlin account and relevant resources

The API for Gremlin account should be created prior to using the Gremlin console. Additionally, it helps to also have the database and graph in place.

[!INCLUDECreate account, database, and graph]

Start and configure the Gremlin console using Docker

For the gremlin console, this quickstart uses the tinkerpop/gremlin-console container image from Docker Hub. This image ensures that you're using the appropriate version of the console (3.4) for connection with the API for Gremlin. Once the console is running, connect from your local Docker host to the remote API for Gremlin account.

  1. Pull the 3.4 version of the tinkerpop/gremlin-console container image.

    docker pull tinkerpop/gremlin-console:3.4
  2. Create an empty working folder. In the empty folder, create a remote-secure.yaml file. Add this YAML configuration to the file.

    hosts: [<account-name>.gremlin.cosmos.azure.com]
    port: 443
    username: /dbs/cosmicworks/colls/products
    password: <account-key>
    connectionPool: {
      enableSsl: true,
      sslEnabledProtocols: [TLSv1.2]
    }
    serializer: {
      className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0,
      config: {
        serializeResultToString: true
      }
    }

    [!NOTE] Replace the <account-name> and <account-key> placeholders with the NAME and KEY values obtained earlier in this quickstart.

  3. Open a new terminal in the context of your working folder that includes the remote-secure.yaml file.

  4. Run the Docker container image in interactive (--interactive --tty) mode. Ensure that you mount the current working folder to the /opt/gremlin-console/conf/ path within the container.

    docker run -it --mount type=bind,source=.,target=/opt/gremlin-console/conf/ tinkerpop/gremlin-console:3.4
  5. Within the Gremlin console container, connect to the remote (API for Gremlin) account using the remote-secure.yaml configuration file.

    :remote connect tinkerpop.server conf/remote-secure.yaml
    

Create and traverse vertices and edges

Now that the console is connected to the account, use the standard Gremlin syntax to create and traverse both vertices and edges.

  1. Add a vertex for a product with the following properties:

    Value
    label product
    id 68719518371
    name Kiama classic surfboard
    price 285.55
    category surfboards
    :> g.addV('product').property('id', '68719518371').property('name', 'Kiama classic surfboard').property('price', 285.55).property('category', 'surfboards')
    

    [!IMPORTANT] Don't foget the :> prefix. THis prefix is required to run the command remotely.

  2. Add another product vertex with these properties:

    Value
    label product
    id 68719518403
    name Montau Turtle Surfboard
    price 600
    category surfboards
    :> g.addV('product').property('id', '68719518403').property('name', 'Montau Turtle Surfboard').property('price', 600).property('category', 'surfboards')
    
  3. Create an edge named replaces to define a relationship between the two products.

    :> g.V(['surfboards', '68719518403']).addE('replaces').to(g.V(['surfboards', '68719518371']))
    
  4. Count all vertices within the graph.

    :> g.V().count()
    
  5. Traverse the graph to find all vertices that replaces the Kiama classic surfboard.

    :> g.V().hasLabel('product').has('category', 'surfboards').has('name', 'Kiama classic surfboard').inE('replaces').outV()
    
  6. Traverse the graph to find all vertices that Montau Turtle Surfboard replaces.

    :> g.V().hasLabel('product').has('category', 'surfboards').has('name', 'Montau Turtle Surfboard').outE('replaces').inV()
    

Clean up resources

When you no longer need the API for Gremlin account, delete the corresponding resource group.

[!INCLUDEDelete account]

How did we solve the problem?

Azure Cosmos DB for Apache Gremlin solved our problem by offering Gremlin as a service. With this offering, you aren't required to stand up your own Gremlin server instances or manage your own infrastructure. Even more, you can scale your solution as your needs grow over time.

To connect to the API for Gremlin account, you used the tinkerpop/gremlin-console container image to run the gremlin console in a manner that didn't require a local installation. Then, you used the configuration stored in the remote-secure.yaml file to connect from the running container the API for Gremlin account. From there, you ran multiple common Gremlin commands.

Next step

[!div class="nextstepaction"] Create and query data using Azure Cosmos DB for Apache Gremlin