Hi there, I am new to Dgraph and having hard time understanding how this type system works
What I want to do
I want to query all nodes having a specific type
What I did
I added one type to Dgraph, User, along with 25 predicates
type User {
id
name
email
phone
login
...
}
id: int @index(int) .
name: string @index(fulltext) .
email: string @index(hash) .
phone: string @index(hash) .
login: string @index(hash) .
....
Then used Live Loader to load json data into dgraph, a sample row:
{
"id": 1,
"name": "Robbert",
"email": "rdelacourt0@about.me",
"phone": "429-267-5796",
"login": "rcreggan0",
....
"dgraph.type": "User"
}
Now, when I run the following query to query how many user nodes I have in the system:
{
count_users(func: type(User)) {
count(uid)
}
}
I get
{
"data": {
"count_users": [
{
"count": 1133110
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 45326,
"processing_ns": 2229090,
"encoding_ns": 105251515,
"total_ns": 107647656
},
"txn": {
"start_ts": 1070210
},
"metrics": {
"num_uids": {
"_total": 0,
"dgraph.type": 0
}
}
}
}
But when I don’t query the node type I get much more bigger number
{
nodeCount(func: has(<age>)) {
nodeCount: count(uid)
}
}
Result
{
"data": {
"nodeCount": [
{
"nodeCount": 17604000
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 49660,
"processing_ns": 54619211815,
"encoding_ns": 1700891760,
"assign_timestamp_ns": 851778,
"total_ns": 56321128868
},
"txn": {
"start_ts": 1070164
},
"metrics": {
"num_uids": {
"_total": 0,
"age": 0
}
}
}
}
Also this query’s metrics confuses me and I don’t know what they mean. I counld’t find anything that explains them
{
nodeCount(func: has(<age>)) @filter(eq(dgraph.type, User)) {
nodeCount: count(uid)
}
}
Result
{
"data": {
"nodeCount": [
{
"nodeCount": 1133110
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 57466,
"processing_ns": 51066224278,
"encoding_ns": 131496865,
"total_ns": 51197953773
},
"txn": {
"start_ts": 1070181
},
"metrics": {
"num_uids": {
"_total": 17604000,
"age": 0,
"dgraph.type": 17604000
}
}
}
}
So, my question is: which query is correct and why the numbers are lower when I query using node type?
Thanks
Dgraph metadata
dgraph version
Dgraph version : v21.12.0
Dgraph codename : zion
Dgraph SHA-256 : 078c75df9fa1057447c8c8afc10ea57cb0a29dfb22f9e61d8c334882b4b4eb37
Commit SHA-1 : d62ed5f15
Commit timestamp : 2021-12-02 21:20:09 +0530
Branch : HEAD
Go version : go1.17.3
jemalloc enabled : true