# Is it possible to do a scripted field for serial difference?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [May 5, 2020, 3:48pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183 "2020-05-05T15:48:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew22](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Andrew22](https://discuss.elastic.co/u/Andrew22)\
**Post date:** [May 5, 2020, 3:48pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183/1 "2020-05-05T15:48:20Z")

</div>

I am new to scripted fields and painless in general and I am wondering if it is possible to do a scripted field for serial difference to use in something where the option is not available like in the graphs?

regards,

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [May 5, 2020, 3:51pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183/2 "2020-05-05T15:51:07Z")

</div>

That's not possible because a scripted field can only act on a single document - for serial difference you would need to "join in" information from other documents which is breaking some basic assumptions of how Elasticsearch works internally.

Using the aggregation is the way to go here. Where exactly do you want to see a serial difference? Maybe there is a work around it.

---

<div class="post-metadata">

**Author:** ![Andrew22](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Andrew22](https://discuss.elastic.co/u/Andrew22)\
**Post date:** [May 7, 2020, 1:31pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183/3 "2020-05-07T13:31:37Z")

</div>

thanks for your reply

i have a counter that I need to know the difference between this latest count and the previous count and I was trying to set up a watcher for it to alert me when it is higher then it has been on average over the previous week

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [May 7, 2020, 1:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183/4 "2020-05-07T13:52:13Z")

</div>

This should be possible to do with the Elasticsearch aggregation type [serial diff](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html)

It should be possible to use aggregations in the input of a watcher.

---

<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 4, 2020, 1:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-scripted-field-for-serial-difference/231183/5 "2020-06-04T13:52:14Z")

</div>

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