Graph Schema Definition

Updated at:

Before using the Lindorm Graph Engine, you must define a schema. This topic describes how to use the HTTP API to initialize a schema, extend or delete properties, add or delete vertex and edge types, query the schema, and clean up subgraph data.

Important

We recommend that you perform schema changes during off-peak hours and reduce or stop read and write operations on the involved types and properties in advance. Do not concurrently perform schema changes. Some schema change operations involve asynchronous data cleanup tasks in the background. Wait for the related background tasks to complete before you perform subsequent change operations.

Note

The Lindorm Graph Engine is currently in gray release. Contact Lindorm technical support (DingTalk: s0s3eg3) for purchase and usage inquiries.

Prerequisites

  • The Lindorm Graph Engine has been activated and the whitelist has been configured.

Initialize the graph schema

Endpoint: /schema/mgmt/apply?db=${DB_NAME}. Defines the complete schema of a subgraph for the first time, including vertex types, edge types, and their connection relationships. The system creates a default subgraph named default. If you do not use the multi-graph feature, all operations are performed on this subgraph.

  • Request format

    curl -X POST "http://${SERVER_HOST}:${GREMLIN_PORT}/schema/mgmt/apply?db=${DB_NAME}" \
      -u ${SUB_USER}:${SUB_PASSWORD} \
      -H "Content-Type: application/json" \
      -d '{
        "vertexLabels": [...],
        "edgeLabels": [...],
        "connections": [...]
      }'
  • Parameters

    Parameter

    Description

    SERVER_HOST

    Server hostname (for example: localhost).

    GREMLIN_PORT

    Gremlin server port (for example: 16032).

    DB_NAME

    Database (subgraph) name. The default value is default.

    SUB_USER

    Authentication username.

    SUB_PASSWORD

    Authentication password.

  • Schema structure definition

    • Example

      The following example defines a social network graph schema that contains two vertex types, person and software, and two edge types, knows and created:

      {
        "vertexLabels": [
          {
            "label": "person",
            "properties": [
              {"name": "name", "dataType": "STRING"},
              {"name": "age",  "dataType": "INT"},
              {"name": "city", "dataType": "STRING", "cardinality": "single"}
            ]
          },
          {
            "label": "software",
            "properties": [
              {"name": "name",  "dataType": "STRING"},
              {"name": "lang",  "dataType": "STRING"},
              {"name": "price", "dataType": "INT"}
            ]
          }
        ],
        "edgeLabels": [
          {
            "label": "knows",
            "properties": [
              {"name": "date",   "dataType": "STRING"},
              {"name": "weight", "dataType": "DOUBLE"}
            ]
          },
          {
            "label": "created",
            "properties": [
              {"name": "date",   "dataType": "STRING"},
              {"name": "weight", "dataType": "DOUBLE"}
            ]
          }
        ],
        "connections": [
          {"edgeLabel": "knows",   "outVertex": "person", "inVertex": "person"},
          {"edgeLabel": "created", "outVertex": "person", "inVertex": "software"}
        ]
      }
  • Schema element descriptions

    Element

    Description

    vertexLabels

    Array of vertex type definitions. Each element describes a vertex type.

    edgeLabels

    Array of edge type definitions. Each element describes an edge type.

    connections

    Array of edge connection relationships. Specifies the source and target vertex types of an edge.

    label

    Label array.

    properties

    Array of property definitions.

    name

    Property field name.

    dataType

    Data type of the property.

    • STRING: string.

    • INT: 32-bit integer.

    • LONG: 64-bit integer.

    • DOUBLE: 64-bit floating-point number.

    • FLOAT: 32-bit floating-point number.

    • BOOLEAN: boolean value.

    • VECTOR_FLOAT: floating-point vector. Must be used with vectorMeta. For details, see the Schema definition with vector capability topic.

    cardinality

    Property value.

    • single (default): single-value property. Each vertex stores only one value for the field.

    • set: multi-value property. Each vertex can store multiple distinct values for the field. The set property is supported only for vertices and is not supported for edge properties.

    outVertex

    Source vertex label of the edge.

    inVertex

    Target vertex label of the edge.

Extend properties for an existing type

Endpoint: POST /schema/mgmt/addProperty?db=${dbName}. /schema/mgmt/apply is used only for the initial setup. To add properties to existing vertex or edge types, use this endpoint. The following examples cover three typical use cases: regular properties, set multi-value properties, and edge property extension.

  • Add regular properties

    • Request format:

      curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "person",
          "labelType": "vertex",
          "properties": [
            {"name": "email", "dataType": "STRING"},
            {"name": "score", "dataType": "DOUBLE"}
          ]
        }'
    • Response example:

      {
        "status": "200 OK",
        "payload": {
          "label": "person",
          "labelType": "vertex",
          "propertiesAdded": ["email", "score"]
        }
      }
  • Add a set property (multi-value property)

    A set property allows a field to store multiple values (such as a list of tags). The set property is supported only for vertices, and labelType must be vertex.

    curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "person",
        "labelType": "vertex",
        "properties": [
          {"name": "tags", "dataType": "STRING", "cardinality": "set"}
        ]
      }'
  • Extend properties for an existing edge type

    Set labelType to edge to extend properties for an edge type. Edges do not support set properties.

    • Request format:

      curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "knows",
          "labelType": "edge",
          "properties": [
            {"name": "since", "dataType": "LONG"}
          ]
        }'
    • Response example:

      {
        "status": "200 OK",
        "payload": {
          "label": "knows",
          "labelType": "edge",
          "propertiesAdded": ["since"]
        }
      }

Delete properties from an existing type

Endpoint: POST /schema/mgmt/delProperty?db=${dbName}. Requires the WRITE permission. Use this endpoint to delete properties from an existing vertex or edge type. After the delete property request succeeds, the related schema takes effect immediately, but the underlying data is cleaned up only after the system completes the COMPACT operation. If you want to accelerate the data cleanup process, you can manually perform the Flush operation and initiate the Compact operation task for the specified type. Before the data is cleaned up, you cannot add a column with the same name to the related type. The endpoint returns the error column is under deleting.

Important
  • You cannot directly delete properties with special identities, such as vector properties and scalar secondary index properties. To delete such properties, you must delete the vertex type or edge type to which the properties belong. Specifically, for scalar secondary index properties, you must first Scalar secondary index for the target property before you can directly delete the property.

  • When you delete properties from an existing vertex type, you must retain at least one property. If you delete all properties, the endpoint returns an error.

  • After you delete properties from an existing vertex type, if a vertex has only the vertex ID and no valid property values, the vertex is silently deleted. Confirm this risk before you perform this operation to avoid data loss.

  • Delete properties from an existing vertex type

    • Request format:

      curl -X POST 'http://${host}:${port}/schema/mgmt/delProperty?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "person",
          "labelType": "vertex",
          "properties": ["email", "price"]
        }'
    • Response example:

      {
        "status": "200 OK",
        "payload": {
          "label": "person",
          "labelType": "vertex",
          "propertiesDeleted": ["email", "price"]
        }
      }
  • Delete properties from an existing edge type

    Set labelType to edge to delete properties from an edge type.

    • Request format:

      curl -X POST 'http://${host}:${port}/schema/mgmt/delProperty?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "knows",
          "labelType": "edge",
          "properties": ["since"]
        }'
    • Response example:

      {
        "status": "200 OK",
        "payload": {
          "label": "knows",
          "labelType": "edge",
          "propertiesDeleted": ["since"]
        }
      }

Add a new vertex type

Endpoint: POST /schema/mgmt/addVertexLabel?db=${dbName}. Creates a new vertex type in an existing subgraph and defines its properties. The system automatically creates the corresponding underlying physical table.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/addVertexLabel?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "product",
        "properties": [
          {"name": "productName", "dataType": "STRING"},
          {"name": "price",       "dataType": "DOUBLE"},
          {"name": "category",    "dataType": "STRING"}
        ]
      }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "vertexLabelCreated": "product",
        "propertiesCount": 3
      }
    }

Delete an existing vertex type

Endpoint: POST /schema/mgmt/delVertexLabel?db=${dbName}. Requires the WRITE permission. Deletes an existing vertex type and its properties from a subgraph. The system automatically deletes the corresponding underlying physical table.

Important

If an associated edge type references the vertex type to be deleted, you cannot delete the vertex type. The endpoint returns an error. You must first delete the related edge types before you can delete the vertex type.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/delVertexLabel?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "product"
      }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "vertexLabelDeleted": "product"
      }
    }

Add a new edge type

Endpoint: POST /schema/mgmt/addEdgeLabel?db=${dbName}. Creates a new edge type in an existing subgraph. The connection field specifies the source and target vertex types, which must already exist; otherwise, the endpoint returns an error.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/addEdgeLabel?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "purchased",
        "properties": [
          {"name": "purchaseDate", "dataType": "STRING"},
          {"name": "quantity",     "dataType": "INT"}
        ],
        "connection": {
          "outVertex": "person",
          "inVertex": "product"
        }
      }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "edgeLabelCreated": "purchased",
        "propertiesCount": 2,
        "connectionRegistered": "person-purchased->product"
      }
    }

    The connectionRegistered field in the response is formatted as ${outVertex}-${edgeLabel}->${inVertex}, which indicates the edge direction that has been successfully registered.

Delete an existing edge type

Endpoint: POST /schema/mgmt/delEdgeLabel?db=${dbName}. Requires the WRITE permission. Deletes an existing edge type and its properties from a subgraph. The system automatically deletes the corresponding underlying physical table.

Important

After the response is returned, the system starts an asynchronous data cleanup task in the background. If the data volume is large, the task takes a long time and affects system throughput. You can use the query asynchronous task progress endpoint to view the cleanup progress. We recommend that you delete edges of the edge type in multiple batches in advance to improve the schema change speed.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/delEdgeLabel?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "purchased"
      }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "edgeLabelDeleted": "purchased"
      }
    }

Perform the Flush operation for a specified type

Endpoint: POST /schema/mgmt/flush?db=${dbName}. Requires the WRITE permission. The Flush operation flushes the stored data of the specified vertex type or edge type to the disk. After the endpoint returns a success response, all online regions in the Graph Engine have completed the Flush operation.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/flush?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "person",
          "labelType": "vertex"
        }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "label": "person",
        "labelType": "vertex",
        "table": "vertex_person",
        "operation": "flush"
      }
    }

Initiate the Compact operation task for a specified type

Endpoint: POST /schema/mgmt/compact?db=${dbName}. Requires the WRITE permission. Forces a Major Compaction on the stored data of the specified vertex type or edge type. The Major Compaction operation merges data files, cleans up deleted or expired data, and releases disk space to improve read and write performance. However, the Major Compaction operation consumes system resources and increases the system load. After the endpoint returns a success response, the Major Compaction task for all online regions in the Graph Engine has been successfully created and is executed asynchronously in the background.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/compact?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "person",
          "labelType": "vertex"
        }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "label": "person",
        "labelType": "vertex",
        "table": "vertex_person",
        "operation": "compact"
      }
    }

Query the progress of an asynchronous task

Endpoint: GET /schema/event/progress?db=${dbName}. Requires the READ permission. Some operations of the Graph Engine start an asynchronous task in the background for execution. You can use this endpoint to query the progress of related tasks by using task parameters. Currently, only the data cleanup task initiated by the delete existing edge type operation is supported (eventType=GRAPH_LABEL_DELETE&labelType=edge).

  • Request format:

    curl -X GET "http://${host}:${port}/schema/mgmt/event/progress?db=default&eventType=GRAPH_LABEL_DELETE&labelType=edge&label=purchased" \
        -u "${user}:${password}"
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "eventType": "GRAPH_LABEL_DELETE",
        "labelType": "edge",
        "label": "purchased",
        "status": "RUNNING"
      }
    }

    The status field in the response indicates the status of the related task. Valid values: PENDING, RUNNING, and NOT_FOUND. The PENDING status may not be queried because the task exists for a very short period of time. When the task is complete, the status changes to NOT_FOUND.

Query the current schema

Endpoint: GET /schema/mgmt/list?db=${dbName}. Requires the READ permission. Returns the complete schema definition of the specified subgraph, including all vertex types, edge types, and their connection relationships.

  • Request format:

    curl -X GET 'http://${host}:${port}/schema/mgmt/list?db=default' \
      -u '${user}:${password}'
  • Response example:

    {
      "payload": {
        "edgeConnections": {
          "created": [
            "person",
            "software"
          ],
          "knows": [
            "person",
            "person"
          ]
        },
        "edgeLabels": {
          "created": [
            {
              "dataType": "STRING",
              "indexBuilt": false,
              "indexed": false,
              "name": "date"
            },
            {
              "dataType": "DOUBLE",
              "indexBuilt": false,
              "indexed": false,
              "name": "weight"
            }
          ],
          "knows": [
            {
              "dataType": "STRING",
              "indexBuilt": false,
              "indexed": false,
              "name": "date"
            },
            {
              "dataType": "DOUBLE",
              "indexBuilt": false,
              "indexed": false,
              "name": "weight"
            }
          ]
        },
        "schemaVersion": 0,
        "vertexLabels": {
          "software": [
            {
              "dataType": "STRING",
              "indexBuilt": false,
              "indexed": false,
              "name": "name"
            },
            {
              "dataType": "STRING",
              "indexBuilt": false,
              "indexed": false,
              "name": "lang"
            },
            {
              "dataType": "INT",
              "indexBuilt": false,
              "indexed": false,
              "name": "price"
            }
          ],
          "person": [
            {
              "dataType": "STRING",
              "indexBuilt": false,
              "indexed": false,
              "name": "name"
            },
            {
              "dataType": "INT",
              "indexBuilt": false,
              "indexed": false,
              "name": "age"
            },
            {
              "dataType": "STRING",
              "indexBuilt": false,
              "indexed": false,
              "name": "city"
            }
          ]
        }
      },
      "status": "200 OK"
    }

    The indexed and indexBuilt fields in the response indicate the index status of each property. indexed indicates whether the property has an index. indexBuilt indicates whether the index data on the property has been built. For more information, see Scalar secondary index.

Clean up subgraph data

Endpoint: /db/del. Quickly cleans up a subgraph. Requires the root account. For the default subgraph default, this endpoint clears the data and deletes the schema definition but retains the subgraph itself. For any other subgraph, the entire subgraph is deleted.

curl -X GET 'http://${host}:${port}/db/del?db=default' \
  -u '${root_user}:${root_password}'