What would be the best way to count the number of unique <entity.type> values?
There are only 3 types (organisation, person and product) but I’d like to know if there is a way to get that number by way of a query.
Thanks, but that’s not quite the count I’m looking for. There are ~250k Entity nodes, each containing an entity.value and an entity.type. I’m not so much interested in figuring out how many Nodes there are of a specific type, but how many unique entity.type string values there are. Suppose we have 5 Entity nodes with the following values:
There are only 3 unique values for entity.type: “person”, “organisation” and “product”. Is there any way of having these three values returned from a query?
Maybe this approach works for you, let me know if don’t.
you have “unique” count using @groupby(name)
{
var(func: anyofterms(name, "Alexei Jack Jose Zoe Ivy")) @groupby(works_for) {
a as count(uid)
}
q(func: uid(a), orderdesc: val(a)) {
name
total_workers : val(a)
workHere: ~works_for @groupby(name){
count(uid)
}
}
}
The Result
This query is not perfect as it exploits an unimplemented feature for this in GroupBy. However, you can use this or expect the GroupBy function to be improved.