In or-tools/Python there is a global constraint solver.Count() which might be used. Example:
the_count = 1 # number of 0's allowed
solver.Add(solver.Count(X1, 0,the_count))
Where "the_count" is the number of 0's to allow in the (flat) array "X1". the_count can be either a constant or a decision variable (so you can constrain that value with further constraints, or just letting the domains do the work of constraining the count, e.g. the domain 1..4 constrain the count to between 1 and 4 occurrences).
"X1" is the array of decision variables which are checked. The second parameter, "0", is the value to count in X.
An example of the usage of solver.Count(): http://hakank.org/or-tools/young_tableaux.py .
There is also a generalization of solver.Count(), namely solver.Distribute (a.k.a. Global Cardinality Count, GCC) where you can count/constrain more than one value at the same time. See my deBruijn sequence model for an example how it's used: http://hakank.org/or-tools/debruijn_binary.py .