# Can I aggregate using only part of a field?

**URL:** <https://discuss.elastic.co/t/can-i-aggregate-using-only-part-of-a-field/171544>\
**Category:** Elasticsearch\
**Created:** [March 8, 2019, 7:01pm UTC](https://discuss.elastic.co/t/can-i-aggregate-using-only-part-of-a-field/171544 "2019-03-08T19:01:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.carey](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@m.carey](https://discuss.elastic.co/u/m.carey)\
**Post date:** [March 8, 2019, 7:01pm UTC](https://discuss.elastic.co/t/can-i-aggregate-using-only-part-of-a-field/171544/1 "2019-03-08T19:01:18Z")

</div>

One of the fields in my index is a version number, e.g. "3.0.7", stored as a keyword. I'd like to do aggregations using only part of the version. For example, I'd like a count of the number of documents for each major version (1.x, 2.x, etc).

I could create separate fields:

major\_version: 3  
minor\_version: 3.0  
patch\_version: 3.0.7

But I'm wondering if there's another way to do this.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 7:15pm UTC](https://discuss.elastic.co/t/can-i-aggregate-using-only-part-of-a-field/171544/2 "2019-03-08T19:15:16Z")

</div>

Another solution would be to use a [Path Tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pathhierarchy-tokenizer.html) with `.` as the delimiter and use [fielddata](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/fielddata.html) to be able to compute aggs. Note that will use more HEAP.

---

<div class="post-metadata">

**Author:** ![m.carey](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@m.carey](https://discuss.elastic.co/u/m.carey)\
**Post date:** [March 8, 2019, 11:44pm UTC](https://discuss.elastic.co/t/can-i-aggregate-using-only-part-of-a-field/171544/3 "2019-03-08T23:44:14Z")

</div>

Brilliant! That's exactly the type of solution I was looking for. Thank you!

---

<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:** [April 6, 2019, 5:07pm UTC](https://discuss.elastic.co/t/can-i-aggregate-using-only-part-of-a-field/171544/5 "2019-04-06T17:07:29Z")

</div>

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