# How does Kibana get available fields stats?

**URL:** <https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766>\
**Category:** Kibana\
**Created:** [February 20, 2017, 3:47pm UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766 "2017-02-20T15:47:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezequielo](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@ezequielo](https://discuss.elastic.co/u/ezequielo)\
**Post date:** [February 20, 2017, 3:47pm UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/1 "2017-02-20T15:47:27Z")

</div>

I am currently working on a search page for my application. Since I already have a front-end I couldn't use Kibana directly, but I like some ideas such as the stats displayed in available fields.

So, how does Kibana gets this info? Is it possible to have those stats for all occurrences in ES?

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [February 20, 2017, 4:15pm UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/2 "2017-02-20T16:15:04Z")

</div>

Hi @ezequielo,

the (experimental) [field stats api](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-stats.html) might be helpful for your purposes. Depending on your specific requirements, the [mapping api](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html) could also be of interest.

---

<div class="post-metadata">

**Author:** ![ezequielo](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@ezequielo](https://discuss.elastic.co/u/ezequielo)\
**Post date:** [February 21, 2017, 8:30am UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/3 "2017-02-21T08:30:24Z")

</div>

I knew about mapping API, actually that's how I am retrieving all fields from my documents. For finding top values I checked [Aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)

This gives me the information I want but it's kind of "manual". I mean I have to first make mappings and then for every field retrieved I have to perform an aggregation query. Is there anything to make it in a single query?

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [February 22, 2017, 11:47am UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/4 "2017-02-22T11:47:57Z")

</div>

The [field stats api](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-stats.html) I linked above should give you the min and max values for each field in one query even for dynamic mappings.

---

<div class="post-metadata">

**Author:** ![ezequielo](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@ezequielo](https://discuss.elastic.co/u/ezequielo)\
**Post date:** [February 23, 2017, 2:20pm UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/5 "2017-02-23T14:20:34Z")

</div>

Thanks @weltenwort. But I am more interested in how many different values and its distribution we have for certain attributes (i.e: country) rather than that kind stats. Maybe my question wasn't clear.

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [February 23, 2017, 3:43pm UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/6 "2017-02-23T15:43:51Z")

</div>

The answers to those questions are quite computationally expensive and highly dependent on the semantics of the individual type. That is why Elasticsearch can not do that for you in the general case. I don't see a way around executing aggregations appropriate for each particular field in your application code.

Also, please note that [cardinality aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html) results are only approximate.

Since you initially asked how Kibana gets the available field stats: It fetches the documents and calculates those stats on the client side right now.

Sorry I can not present you with a more satisfying solution.

---

<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:** [March 23, 2017, 3:44pm UTC](https://discuss.elastic.co/t/how-does-kibana-get-available-fields-stats/75766/7 "2017-03-23T15:44:23Z")

</div>

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