I’ll reply to myself, so others will be able to find the solution.
After reading the code of the live updater, I figured how everything should be configured.
- Each object in the json must have
dgraph.typespecified - If upsert is intended, you need to provide a
uidfor each object. The easiest way is provide it in a form of blank node_:<any string> - If you want to have a separate unique global index by some field, you want to add
@dgraph(pred: "<global id predicate name>")and you don’t want to specify this predicate on each object by yourself in json. You should also add a flag to the live uploader (--upsertPredicate <global id predicate name>), so your predicate will be queryable.
In my example I did:
Schema:
interface IdentifiedObject {
id: ID!
iri: String! @id @dgraph(pred: "xid")
description: String
name: String
}
type BaseVoltage implements IdentifiedObject {
id: ID!
iri: String! @id @dgraph(pred: "xid")
description: String
name: String
nominalVoltage: Voltage
}
type ACLineSegment implements IdentifiedObject {
id: ID!
iri: String! @id @dgraph(pred: "xid")
BaseVoltage: BaseVoltage
Terminals: [Terminal!]
description: String
name: String
}
Data:
[
{
"uid": "_:urn:uuid:0043d68c-2d4c-4965-9c8a-e1fca6ecd178",
"dgraph.type": "ACLineSegment",
"IdentifiedObject.iri": "urn:uuid:0043d68c-2d4c-4965-9c8a-e1fca6ecd178",
"IdentifiedObject.name": "110 kV C.D. Tamaya-Salar",
"ACLineSegment.BaseVoltage": {
"uid": "_:urn:uuid:01bb6a99-59af-7681-acb7-5a157aa705aa",
"dgraph.type": "BaseVoltage",
"IdentifiedObject.iri": "urn:uuid:01bb6a99-59af-7681-acb7-5a157aa705aa",
"IdentifiedObject.name": "110.00 kV",
"BaseVoltage.nominalVoltage": null
},
},
{
"uid": "_:urn:uuid:0084d6fc-e131-432d-92bb-1e0a12dc95db",
"dgraph.type": "ACLineSegment",
"IdentifiedObject.iri": "urn:uuid:0084d6fc-e131-432d-92bb-1e0a12dc95db",
"IdentifiedObject.name": "EST.67 - EST.74 110KV C1",
"ACLineSegment.BaseVoltage": {
"uid": "_:urn:uuid:01bb6a99-59af-7681-acb7-5a157aa705aa",
"dgraph.type": "BaseVoltage",
"IdentifiedObject.iri": "urn:uuid:01bb6a99-59af-7681-acb7-5a157aa705aa",
"IdentifiedObject.name": "110.00 kV",
"BaseVoltage.nominalVoltage": null
},
},
]
Command:
❯ docker exec dgraph dgraph live --alpha localhost:9080 --format=json -f /tmp/data.json --upsertPredicate xid
After that my queries for BaseVoltage nodes return exactly one node.