# Is it possible to get last text field value on a transform aggregation?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-get-last-text-field-value-on-a-transform-aggregation/231717>\
**Category:** Elasticsearch\
**Created:** [May 8, 2020, 12:22pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-last-text-field-value-on-a-transform-aggregation/231717 "2020-05-08T12:22:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xavier\_Marti\_Bofill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavier_marti_bofill/32/67923_2.png) [@Xavier\_Marti\_Bofill](https://discuss.elastic.co/u/Xavier_Marti_Bofill)\
**Post date:** [May 8, 2020, 12:22pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-last-text-field-value-on-a-transform-aggregation/231717/1 "2020-05-08T12:22:36Z")

</div>

Imagine we have an ecommerce, and an index with a document per every sale, with **user** and **product** fields. For each user I'd like to always know which is the last product they bought.  
How could we tackle that?

---

<div class="post-metadata">

**Author:** ![Hendrik\_Muhs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hendrik_muhs/32/25802_2.png) [@Hendrik\_Muhs](https://discuss.elastic.co/u/Hendrik_Muhs)\
**Post date:** [May 8, 2020, 3:40pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-last-text-field-value-on-a-transform-aggregation/231717/2 "2020-05-08T15:40:17Z")

</div>

Have a look at this:

[https://www.elastic.co/guide/en/elasticsearch/reference/7.7/transform-painless-examples.html#painless-top-hits](https://www.elastic.co/guide/en/elasticsearch/reference/7.7/transform-painless-examples.html#painless-top-hits)

This is part of the 7.7 documentation, however should work in older versions, too.

---

<div class="post-metadata">

**Author:** ![Xavier\_Marti\_Bofill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavier_marti_bofill/32/67923_2.png) [@Xavier\_Marti\_Bofill](https://discuss.elastic.co/u/Xavier_Marti_Bofill)\
**Post date:** [May 8, 2020, 4:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-last-text-field-value-on-a-transform-aggregation/231717/3 "2020-05-08T16:05:03Z")

</div>

Awesome, thanks!

---

<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:** [June 5, 2020, 4:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-last-text-field-value-on-a-transform-aggregation/231717/4 "2020-06-05T16:05:07Z")

</div>

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