Updated on 2024-01-04 GMT+08:00

Adding Edges in Batches

Function

This API is used to add edges in batches.

URI

POST /ges/v1.0/{project_id}/graphs/{graph_name}/edges/action?action_id=batch-add
Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

graph_name

Yes

String

Graph name

Request Parameters

Parameter

Mandatory

Type

Description

edges

Yes

Object

Edge array to be added

parallelEdge

No

parallelEdge Object

Repetitive edge processing

createNotExists

No

Boolean

Whether to add source or target vertices that do not exist in the edges parameter before adding edges. The default value is false, which does not affect the original functions and semantics.

If this parameter is set to true, source or target vertices that do not exist in the edges parameter are added prior to the edges.

Table 2 edges parameter description

Parameter

Mandatory

Type

Description

source

Yes

String

Source vertex of an edge

target

Yes

String

Target vertex of an edge

label

Yes

String

Edge label

properties

No

Object

Value of each property

Table 3 parallelEdge parameter description

Parameter

Mandatory

Type

Description

action

No

String

Processing mode of repetitive edges. The value can be allow, ignore, or override. The default value is allow.

  • allow indicates that repetitive edges are allowed.
  • ignore indicates that subsequent repetitive edges are ignored.
  • override indicates that the previous repetitive edges are overwritten.

ignoreLabel

No

Boolean

Whether to ignore labels on repetitive edges. The value is true or false, and the default value is true.

  • true: Indicates that the repetitive edge definition does not contain the label. That is, the <source vertex, target vertex> indicates an edge, excluding the label information.
  • false: indicates that the repetitive edge definition contains the label. That is, <Source vertex, Target vertex, Label> indicates an edge.

targetProperties

No

targetProperties Array

Properties used to determine duplicate edges. If this parameter is specified, ignoreLabel is set to false to define repetitive edges that contain properties in the list specified by this parameter.

(This parameter is mandatory only when action is set to override.)

NOTE:
  • The current version supports only overwriting by property and does not support ignoring by property. In addition, only one property takes effect for each label.
  • Properties of the non-single type are considered unequal.
Table 4 targetProperties parameter description

Parameter

Mandatory

Type

Description

label

Yes

String

Labels whose repetitive edges need to be determined by property

properties

Yes

Array

List of properties whose repetitive edges need to be determined by property. Currently, only one property is supported. If multiple properties are entered, the first property is used.

Response Parameters

Table 5 Response body parameters

Parameter

Type

Description

errorMessage

String

System prompt.

  • If execution succeeds, this parameter may be left blank.
  • If execution fails, this parameter is used to display the error message.

errorCode

String

System prompt code.

  • If execution succeeds, this parameter may be left blank.
  • If execution fails, this parameter is used to display the error code.

result

String

Request result. If the request is successful, the value is success. If the request fails, the value is failed.

Example Request

Add edges in batches. The source vertex is 46, the target vertices are 39 and 38, and the edge label is rate.

POST http://{SERVER_URL}/ges/v1.0/{project_id}/graphs/{graph_name}/edges/action?action_id=batch-add
{
    "parallelEdge": {
        "action": "override",
        "ignoreLabel": false,
        "targetProperties": [
            {
                "label": "rate",
                "properties": [
                    "Datetime"
                ]
            },
            {
                "label": "superclassOf",
                "properties": [
                    "popularity"
                ]
            }
        ]
    },
    "createNotExists": true,
    "edges": [
        {
            "source": "46",
            "target": "39",
            "label": "rate",
            "properties": {
                "Rating": [
                    5
                ],
                "Datetime": [
                    "2018-01-01 20:30:05"
                ]
            }
        },
        {
            "source": "46",
            "target": "39",
            "label": "rate",
            "properties": {
                "Rating": [
                    4
                ],
                "Datetime": [
                    "2018-01-01 20:30:05"
                ]
            }
        }
    ]
}
  • SERVER_URL: Address for accessing a graph. For details about its value, see Using Service Plane APIs.
  • In the example, if vertices 666 and 777 are not in the original graph, create vertices 666 and 777, retain the default value of each label, and add an edge.

Example Response

Status code: 200

Example response for a successful request

Http Status Code: 200
{
 "result":"success",
 "data": {
     "edges": [
         {
             "index": "7",
             "source": "46",
             "target": "39"
         },
         {
             "index": "0",
             "source": "46",
             "target": "38"
         }
     ]
 }
}

Status code: 400

Example response for a failed request

Http Status Code: 400
{
 "errorMessage":"edge source vertex [Lily] does not exist",
 "errorCode":"GES.8000"
}

Status Codes

Return Value

Description

400 Bad Request

Request error.

401 Unauthorized

Authorization failed.

403 Forbidden

No operation permissions.

404 Not Found

No resources found.

500 Internal Server Error

Internal server error.

503 Service Unavailable

Service unavailable.

Error Codes

See Error Codes.