# Painless scripting - how to compare two different fields present in two different documents of an index

**URL:** <https://discuss.elastic.co/t/painless-scripting-how-to-compare-two-different-fields-present-in-two-different-documents-of-an-index/112026>\
**Category:** Elasticsearch\
**Created:** [December 15, 2017, 5:38pm UTC](https://discuss.elastic.co/t/painless-scripting-how-to-compare-two-different-fields-present-in-two-different-documents-of-an-index/112026 "2017-12-15T17:38:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikrishnagaddipati](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@saikrishnagaddipati](https://discuss.elastic.co/u/saikrishnagaddipati)\
**Post date:** [December 15, 2017, 5:38pm UTC](https://discuss.elastic.co/t/painless-scripting-how-to-compare-two-different-fields-present-in-two-different-documents-of-an-index/112026/1 "2017-12-15T17:38:56Z")

</div>

Hi , I want to compare field 'start\_time' present in document 'A' and field 'end\_time' present document 'B' and get the result as new field in the document using painless scripting. I am using scripted fields in kibana to achieve this. Did anyone tried this before?

I am using elasticsearch 5.6.4

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 15, 2017, 10:53pm UTC](https://discuss.elastic.co/t/painless-scripting-how-to-compare-two-different-fields-present-in-two-different-documents-of-an-index/112026/2 "2017-12-15T22:53:52Z")

</div>

Scripting allows generating dynamic values for a single document. There is no way to run a script that operates on multiple documents at the same time.

---

<div class="post-metadata">

**Author:** ![saikrishnagaddipati](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@saikrishnagaddipati](https://discuss.elastic.co/u/saikrishnagaddipati)\
**Post date:** [December 15, 2017, 11:01pm UTC](https://discuss.elastic.co/t/painless-scripting-how-to-compare-two-different-fields-present-in-two-different-documents-of-an-index/112026/3 "2017-12-15T23:01:13Z")

</div>

@rjernst what would be the best way to do it? appreciate your quick response.

---

<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:** [January 12, 2018, 11:01pm UTC](https://discuss.elastic.co/t/painless-scripting-how-to-compare-two-different-fields-present-in-two-different-documents-of-an-index/112026/4 "2018-01-12T23:01:36Z")

</div>

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