# ES cardinality got zero when set precision\_threshold large

**URL:** <https://discuss.elastic.co/t/es-cardinality-got-zero-when-set-precision-threshold-large/179028>\
**Category:** Elasticsearch\
**Created:** [April 30, 2019, 6:57am UTC](https://discuss.elastic.co/t/es-cardinality-got-zero-when-set-precision-threshold-large/179028 "2019-04-30T06:57:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![li\_zhengqiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/li_zhengqiu/32/45292_2.png) [@li\_zhengqiu](https://discuss.elastic.co/u/li_zhengqiu)\
**Post date:** [April 30, 2019, 6:57am UTC](https://discuss.elastic.co/t/es-cardinality-got-zero-when-set-precision-threshold-large/179028/1 "2019-04-30T06:57:40Z")

</div>

Hello,  
My elasticsearch' version is 6.2.4, like the title said, there is something wrong with the cardinality aggregation. When I change the precision\_threshold from 300 to 10000, I got zero for the cardinality. I suppose that the higher the precision\_threshold will lead to a more accurate result, but the only I can get is zero. Below is the code:

```
    dsl={
  'query': {
    'bool': {
      'must': [
        {
          'range': {
            'created': {
              'gte': '2019-04-30',
              'lte': '2019-04-30',
              'format': 'yyyy-MM-dd',
              'time_zone': '+08:00'
            }
          }
        },
        {
          'terms': {
            'app_name': [
              'vip-mini'
            ]
          }
        },
        {
          'terms': {
            'current_page': [
              'detail'
            ]
          }
        },
        {
          'terms': {
            'event_type': [
              'pv'
            ]
          }
        }
      ]
    }
  },
  'aggs': {
    'my_buckets': {
      'composite': {
        'size': 9999999,
        'sources': [
          {
            '日期': {
              'date_histogram': {
                'field': 'created',
                'interval': '1d',
                'time_zone': '+08:00'
              }
            }
          },
          {
            'current_page': {
              'terms': {
                'field': 'current_page'
              }
            }
          }
        ]
      },
      'aggregations': {
        '(UV)': {
          'cardinality': {
            'field': 'user_id',
            "precision_threshold": 10000,
            "missing": "N/A"
          }
        },
        '(Visitor)': {
          'cardinality': {
            'field': 'session_id',
            "precision_threshold": 10000,
            "missing": "N/A"
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 30, 2019, 7:09am UTC](https://discuss.elastic.co/t/es-cardinality-got-zero-when-set-precision-threshold-large/179028/2 "2019-04-30T07:09:07Z")

</div>

Looks like you have a time interval of zero length which I assume lead to no matches.

---

<div class="post-metadata">

**Author:** ![li\_zhengqiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/li_zhengqiu/32/45292_2.png) [@li\_zhengqiu](https://discuss.elastic.co/u/li_zhengqiu)\
**Post date:** [April 30, 2019, 7:16am UTC](https://discuss.elastic.co/t/es-cardinality-got-zero-when-set-precision-threshold-large/179028/3 "2019-04-30T07:16:51Z")

</div>

It is gte(\>=) and lte(\<=) so, I think it is ok. And also, when I only change precision\_threshold from 10000 to 100, the result is not zero.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 28, 2019, 7:28am UTC](https://discuss.elastic.co/t/es-cardinality-got-zero-when-set-precision-threshold-large/179028/4 "2019-05-28T07:28:57Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
