# Compare fields in two documents?

**URL:** <https://discuss.elastic.co/t/compare-fields-in-two-documents/116548>\
**Category:** Kibana\
**Created:** [January 22, 2018, 10:49pm UTC](https://discuss.elastic.co/t/compare-fields-in-two-documents/116548 "2018-01-22T22:49:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [January 23, 2018, 10:00am UTC](https://discuss.elastic.co/t/compare-fields-in-two-documents/116548/2 "2018-01-23T10:00:24Z")

</div>

Scripted fields can only calculate data WITHIN one document. You CANNOT calculate data across multiple documents.

To achieve writing that diff, you will need to measure it before indexing the documents, so that you write the time diff to the ending document.

In Logstash e.g. the [elapsed](https://www.elastic.co/guide/en/logstash/current/plugins-filters-elapsed.html) plugin can achieve that.

Cheers,  
Tim

---

_[View the full topic](https://discuss.elastic.co/t/compare-fields-in-two-documents/116548)._
