# Field stats search in ES 6.X?

**URL:** <https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323>\
**Category:** Elasticsearch\
**Created:** [March 2, 2018, 9:21pm UTC](https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323 "2018-03-02T21:21:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fassisrosa](https://avatars.discourse-cdn.com/v4/letter/f/a87d85/32.png) [@fassisrosa](https://discuss.elastic.co/u/fassisrosa)\
**Post date:** [March 2, 2018, 9:21pm UTC](https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323/1 "2018-03-02T21:21:09Z")

</div>

Hi there,

In previous versions of ES, fields stats were used internally by ES to determine which indexes to use when searching. A typical example for timeseries indexes would be to search on a time range, internal field stats would be used to not even attempt searching on indexes for which the time range did not match. The field stats API is gone in more recent versions of ES. Two questions:

\*) Does ES still do a smart selection of indexes to avoid touching ES on time range queries based on field statistics for each index?

\*) If I want to have access to those per index field stats, is there any way to do it in 5.6.X and 6.X?

Thanks,

Francisco.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [March 3, 2018, 6:50pm UTC](https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323/2 "2018-03-03T18:50:16Z")

</div>

> [@fassisrosa](#):
>
> \*) Does ES still do a smart selection of indexes to avoid touching ES on time range queries based on field statistics for each index?

Yep! As part of the change, we introduced a new pre-filter phase that executes to find "matching" shards. Each shard can evaluate the query from a high-level and see if it potentially has matching documents (e.g. has documents in the correct time range). The shards that don't have any potentially matching docs will be skipped for the main search phase.

More details here: [https://github.com/elastic/elasticsearch/pull/25658](https://github.com/elastic/elasticsearch/pull/25658)

> [@fassisrosa](#):
>
> \*) If I want to have access to those per index field stats, is there any way to do it in 5.6.X and 6.X?

If you need the field-stats style data, the best way to do it now is just via an aggregation for most of the stats (doc counts, min/max time range, etc). You can also use TermVectors if you need stats about the terms themselves.

---

<div class="post-metadata">

**Author:** ![fassisrosa](https://avatars.discourse-cdn.com/v4/letter/f/a87d85/32.png) [@fassisrosa](https://discuss.elastic.co/u/fassisrosa)\
**Post date:** [March 3, 2018, 7:07pm UTC](https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323/3 "2018-03-03T19:07:43Z")

</div>

Thanks so much for your answer! Exactly what I was looking for! 👍

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [March 3, 2018, 7:20pm UTC](https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323/4 "2018-03-03T19:20:40Z")

</div>

Np, happy to help! 🙂

---

<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 31, 2018, 7:20pm UTC](https://discuss.elastic.co/t/field-stats-search-in-es-6-x/122323/5 "2018-03-31T19:20:47Z")

</div>

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