dgraph-io/dgraph · error
Expected 1 child for not but got %d.
Error message
Expected 1 child for not but got %d.
What it means
The facet filter tree builder validates boolean operator arity: a `not` node must have exactly one child. Receiving 0 or 2+ children under a not means the parsed query's boolean structure is malformed for facets.
Source
Thrown at worker/task.go:2483
default:
return nil, errors.Errorf("Fn %s not supported in preprocessFilter.", fname)
}
return ftree, nil
}
for _, c := range tree.Children {
ftreec, err := preprocessFilter(c)
if err != nil {
return nil, err
}
ftree.children = append(ftree.children, ftreec)
}
numChild := len(tree.Children)
switch ftree.op {
case "not":
if numChild != 1 {
return nil, errors.Errorf("Expected 1 child for not but got %d.", numChild)
}
case "and":
if numChild != 2 {
return nil, errors.Errorf("Expected 2 child for not but got %d.", numChild)
}
case "or":
if numChild != 2 {
return nil, errors.Errorf("Expected 2 child for not but got %d.", numChild)
}
default:
return nil, errors.Errorf("Unsupported operation in facet filtering: %s.", tree.Op)
}
return ftree, nil
}
type countParams struct {
readTs uint64
counts []int64View on GitHub (pinned to 759e242be6)
Solutions
- Give `not` exactly one operand: @facets(not(eq(name, "x"))).
- Wrap a multi-condition negation in parentheses: @facets(not((eq(a,"1") OR eq(b,"2")))).
- Check the query generator's parenthesis emission for NOT.
Example fix
// before @facets(not(eq(a, "1") AND eq(b, "2"))) // after @facets(not((eq(a, "1") AND eq(b, "2"))))
Defensive patterns
Strategy: validation
Validate before calling
function validateNotArity(tree) {
if (tree.op === "not" && tree.children.length !== 1)
throw new Error("not must have exactly 1 child in facet filter");
(tree.children || []).forEach(validateNotArity);
} Try / catch
try {
return await txn.query(query);
} catch (e) {
if (/Expected 1 child for not/.test(String(e))) {
// fix boolean nesting in the query generator
}
throw e;
} Prevention
- Always wrap multi-operand negations in parentheses.
- Ensure NOT nodes in query builders emit exactly one child.
- Add AST-arity unit tests for NOT in generated queries.
When it happens
Trigger: A query like @facets(not(a AND b)) constructed so `not` wraps multiple children, or an empty/invalid not expression reaching preprocessFilter.
Common situations: Hand-written queries with ambiguous nesting; generated queries from ORMs/tools that mis-parenthesize NOT; converting SQL NOT IN patterns to Dgraph facet syntax.
Related errors
- Expected 2 child for not but got %d.
- Cannot specify order at both args and facets
- One argument expected in %s, but got %d.
- Fn %s not supported in preprocessFilter.
- Unsupported operation in facet filtering: %s.
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/fbce83144d7af614.
Report an issue: GitHub.