Upsert many edges with discriminators in RESTPP

Hi, Team!

I refer to this document Upsert data to graph :: TigerGraph DB
First of all, the example of @add_id6.json is not shown in the document. I don’t know what it is.

I refer docs to construct an upsert request for RESTPP,
There is no example of updating multiple edges with the discriminator flag from one source vertex to another target vertex.

Here is my example:

CREATE DIRECTED EDGE SampleEdge(FROM SourceVertexType, TO TargetVertexType, DISCRIMINATOR(field1 STRING, field2 STRING), field3 STRING)

edge list:

SourceVertexType,TargetVertexType, field1, field2, field3
id1, id2, q1, q2, timestamp1
id1, id2, q1, q3, timestamp1
id1, id2, q1, q4, timestamp1

use DISCRIMINATOR, these are three different edges distinguished by DISCRIMINATOR() between id1 and id2. Now I need to construct a RESTPP upsert request and insert them in the same request json, but the example provided upsert request does not satisfy

This is the build request, only for this edge (it seems that there is no space to insert the remaining edges, and they will either be overwritten or ignored, because TargetVertexType uses id2 distinction)

id1, id2, q1, q2, timestamp1
{
	"vertices": {
		"SourceVertexType": {
			"id1": {
				"id": {
					"value": 1
				}
			}
		},
		"TargetVertexType": {
			"id2": {
				"id": {
					"value": 2
				}
			}
		}
	},
	"edges": {
		"SourceVertexType": {
			"id1": {
				"SampleEdge": {
					"TargetVertexType": {
						"id2": {
							"field1": {
								"value": "q1"
							},
							"field2": {
								"value": "q2"
							},
							"field3": {
								"value": "timestamp1"
							}
						}
					}
				}
			}
		}
	}
}

My question is how to construct updating multiple edges with the discriminator, I can insert 3 edges at once.

Hi Zella,

The add_id6.json is provided in text, you can find the contents of the document with this direct hyperlink.

To add multiple edges in the same request you can add the additional edges into your json payload like such:

{
	"edges": {
		"user": {
			"id1": {
				"has_edge": {
					"user": {
						"id2": {
							"field1": {
								"value": "q8"
							},
							"field2": {
								"value": "q7"
							},
							"field3": {
								"value": "timestamp1"
							}
						}, 
					}
				}
			}
		}, 
        "user": {
			"id1": {
				"has_edge": {
					"user": {
						"id2": {
							"field1": {
								"value": "q9"
							},
							"field2": {
								"value": "q10"
							},
							"field3": {
								"value": "timestamp2"
							}
						}, 
					}
				}
			}
		}
	}
}```

Hi hshakoor, thank you for your reply.

As you constructed “To add multiple edges in the same request”, I think it is impossible to construct this json request, because edges.user.id1 cannot appear twice in the map structure at the same time, has_edge:e2 will cover the value of has_edge:e1 instead of existing at the same time

{
	"edges": {
		"user": {
			"id1": {
				"has_edge": {
					"user": {
						"id2": { has_edge:e1 attributes ...}, 
					}
				}
			}
		}, 
        "user": {
			"id1": {
				"has_edge": {
					"user": {
						"id2": {  has_edge:e2 attributes ... }, 
					}
				}
			}
		}
	}
}

My requirement is that when I create an EdgeType containing a discriminator and want to add two edges at the same time, when the start and end vertex these (start-end) tuple were not repeat, I have successfully inserted multiple edges.

But for the same starting vertex id1 and target vertex id2, inserting two has_edges with discriminator properties, I still didn’t find a solution

user:id1 - has_edge:e1 - user:id2
user:id1 - has_edge:e2 - user:id2

has_edge:e1 and e2
The data structure provided by tigergraph
{“edges”: { “user”: … }}
edges is a map structure, the first layer is SourceVertexType ( in this example is user)
There is no way to have two has_edges at the same time like the json you constructed
When they construct the request, has_edge:e2 will cover has_edge:e1 and cannot exist at the same time. Because “user” as SourceVertexType only exists once in the map.

In addition, I jumped to check from this link Upsert data to graph :: TigerGraph DB, but unfortunately
I only saw in the documents
curl -X POST --data-binary @add_id6.jsonhttp://localhost:9000/graph?vertex_must_exist=true
and its Response, but did not see the Request text of @add_id6.json