[GitHub] Tracking zero counts

Moved from GitHub dgraph/5114

Posted by mehdiym:

Hello,

When using the count index at the query root, I regularly need to get values lower than a threshold, including zero.

For instance, suppose I have products connected to suppliers and I’d like to known when there are not enough suppliers. I could use the following query:

{
  me(func:lt(count(supplier), 3)) {
    uid
    product_name
  }
}

But I will miss the products with 0 suppliers: the most important ones to me.

I could use a second query block with a filter not has(supplier) but it is no efficient as not using any index.

What about adding an option on @count index to also track 0 counts?
It could be tracked only for the types containing the predicates with those indexes.

For example :

type Product {
  supplier
}
supplier: [uid] @count(zero) .

Original forum thread: Tracking zero counts

1 Like

lgalatin commented :

I am accepting it for now which means we will work on it if it gets high priority. will keep you posted.

lgalatin commented :

This was given low priority for now, would you please let us know if the suggestions given in the discuss post work for you?