upsert {
query {
q1(func: eq(ip, "127.5.5.300")) {
v1 as uid
}
q2(func: eq(ip, "127.5.5.400")) {
v2 as uid
}
q3(func: eq(port, "12001")) {
v3 as uid
firstlink_var as firstlink
visitcount_var as visitcount
}
s(){
countsum_var as sum(val(visitcount_var))
currcount_var as math(countsum_var+100)
}
}
mutation @if(eq(len(firstlink_var), 0)){
set {
uid(v1) <ip> "127.5.5.300" .
uid(v1) <serverId> "i-adkuwdewg" .
uid(v1) <dgraph.type> "IP" .
uid(v1) <pin> "wangjinsong1" .
uid(v2) <ip> "127.5.5.400" .
uid(v2) <serverId> "i-au43wdewg" .
uid(v2) <dgraph.type> "IP" .
uid(v2) <pin> "wangjinsong1" .
uid(v3) <port> "12001" .
uid(v3) <visitcount> "100" .
uid(v3) <proto> "TCP" .
uid(v3) <firstlink> "1111111" .
uid(v3) <lastlink> "1111111" .
uid(v3) <dgraph.type> "PORT" .
uid(v3) <pin> "wangjinsong1" .
uid(v1) <visit> uid(v3) .
uid(v3) <belong> uid(v2) .
}
}
mutation @if(gt(len(firstlink_var), 0)){
set {
uid(v1) <ip> "127.5.5.300" .
uid(v1) <serverId> "i-adkuwdewg" .
uid(v1) <dgraph.type> "IP" .
uid(v1) <pin> "wangjinsong1" .
uid(v2) <ip> "127.5.5.400" .
uid(v2) <serverId> "i-au43wdewg" .
uid(v2) <dgraph.type> "IP" .
uid(v2) <pin> "wangjinsong1" .
uid(v3) <port> "12001" .
uid(v3) <visitcount> val(currcount_var) .
uid(v3) <proto> "TCP" .
uid(v3) <firstlink> val(firstlink_var) .
uid(v3) <lastlink> "2222222" .
uid(v3) <dgraph.type> "PORT" .
uid(v3) <pin> "wangjinsong1" .
uid(v1) <visit> uid(v3) .
uid(v3) <belong> uid(v2) .
}
}
}
upsert {
query {
q1(func: eq(ip, "127.0.0.100")) {
v1 as uid
}
q2(func: eq(ip, "127.0.0.200")) {
v2 as uid
}
q3(func: eq(port, "9000")) {
v3 as uid
firstlink3 as firstlink
countx as count(visitcount)
count3 as math(countx+100)
}
}
mutation @if(eq(len(firstlink3), 0)){
set {
uid(v1) <ip> "127.0.0.100" .
uid(v1) <serverId> "i-adkuwdewg" .
uid(v1) <dgraph.type> "IP" .
uid(v2) <ip> "127.0.0.200" .
uid(v2) <serverId> "i-au43wdewg" .
uid(v2) <dgraph.type> "IP" .
uid(v3) <port> "9000" .
uid(v3) <visitcount> "100" .
uid(v3) <proto> "TCP" .
uid(v3) <firstlink> "1111111" .
uid(v3) <lastlink> "1111111" .
uid(v3) <dgraph.type> "VISIT" .
uid(v1) <visit> uid(v3) .
uid(v3) <visit> uid(v2) .
}
}
mutation @if(gt(len(firstlink3), 0)){
set {
uid(v1) <ip> "127.0.0.100" .
uid(v1) <serverId> "i-adkuwdewg" .
uid(v1) <dgraph.type> "IP" .
uid(v2) <ip> "127.0.0.200" .
uid(v2) <serverId> "i-au43wdewg" .
uid(v2) <dgraph.type> "IP" .
uid(v3) <port> "9000" .
uid(v3) <visitcount> val(count3) .
uid(v3) <proto> "TCP" .
uid(v3) <firstlink> val(firstlink3) .
uid(v3) <lastlink> "2222222" .
uid(v3) <dgraph.type> "VISIT" .
uid(v1) <visit> uid(v3) .
uid(v3) <visit> uid(v2) .
}
}
}
upsert {
query {
q1(func: eq(name, "1231.123.123.123")) {
v1 as uid
agex as count(age)
age1 as math(agex + 1200)
email1 as email
}
q2(func: eq(name, "111.111.111.111")) {
v2 as uid
}
}
mutation @if(eq(len(age1), 0)){
set {
uid(v1) <name> "1231.123.123.123" .
uid(v1) <age> "10" .
uid(v1) <dgraph.type> "Person" .
uid(v1) <email> val(email1) .
uid(v2) <name> "111.111.111.111" .
uid(v2) <age> "20" .
uid(v2) <dgraph.type> "Person" .
uid(v2) <email> "user_email1@company1.io" .
uid(v1) <friend> uid(v2) .
}
}
mutation @if(gt(len(age1), 0)){
set {
uid(v1) <name> "123.123.123.123" .
uid(v1) <age> val(age1) .
uid(v1) <dgraph.type> "Person" .
uid(v1) <email> val(email1) .
uid(v2) <name> "111.111.111.111" .
uid(v2) <age> "20" .
uid(v2) <dgraph.type> "Person" .
uid(v2) <email> "user_email1@company1.io" .
uid(v1) <friend> uid(v2) .
}
}
}
upsert {
query {
q1(func: eq(name, "33.33.33.33")) {
v1 as uid
friend @filter(eq(name, "222.2.2.2")) @facets(firstlink:firstlinkx) {
name
}
}
q2(func: eq(name, "222.2.2.2")) {
v2 as uid
}
}
mutation{
set {
uid(v1) <name> "33.33.33.33" .
uid(v1) <dgraph.type> "Person" .
uid(v1) <email> "user_email1@company1.io" .
uid(v2) <name> "222.2.2.2" .
uid(v2) <dgraph.type> "Person" .
uid(v2) <email> "user_email1@company1.io" .
uid(v1) <friend> uid(v2) (firstlinkx=4444, lastlinkx=3333) .
}
}
}