Skip to main content

Error message

{context}: approx_count_distinct and count_distinct cannot both be enabled
Example: defaults: approx_count_distinct and count_distinct cannot both be enabled

When this error occurs

approx_count_distinct uses HyperLogLog for fast approximate cardinality. count_distinct computes the exact value. Enabling both on the same scope is redundant and indicates a configuration mistake, so the server rejects it. This validation applies at every level: defaults, namespace scope, field overrides, and nested nodes.

Example: request that triggers this error

{
  "defaults": {
    "enabled_stats": [
      "value_count",
      "approx_count_distinct",
      "count_distinct"
    ]
  },
  "refresh": { "trigger": "manual" }
}

How to fix

Choose one of the two:
  • approx_count_distinct — faster, suitable for large datasets where an estimate is acceptable
  • count_distinct — exact, more expensive to compute
{
  "defaults": {
    "enabled_stats": ["value_count", "approx_count_distinct"]
  },
  "refresh": { "trigger": "manual" }
}