# Painless Script for Comparing Nested Objects

**URL:** https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608
**Category:** Kibana
**Created:** [November 17, 2020, 1:06am UTC](https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608 "2020-11-17T01:06:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![edbautista](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@edbautista](https://discuss.elastic.co/u/edbautista)
#### Post date: [November 17, 2020, 1:06am UTC](https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608/1 "2020-11-17T01:06:50Z")

</div>

Hi,

We have a use case where we need to compare two dates that are inside a nested field and show the result to another field. Generally, if time1 \> time2, it would show 'Incorrect', and 'Correct' otherwise. Here is my working script:

```auto
if (params._source['a.time1'].value.getMillis() >=
params._source['b.time2'].value.getMillis()) {
   return 'Incorrect'
}
else {
   return 'Correct'
}

```

Since it's in a nested field, I used params.\_source instead of doc. When I save and run the script, the other fields from the index are somewhat removed from the Discover page. Only the scripted field is shown without any value. I've modified the script to cater to non-nested objects and the script worked properly. Is there a way to call nested objects and use them in painless? Thank you.

---

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [November 19, 2020, 5:04pm UTC](https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608/2 "2020-11-19T17:04:01Z")

</div>

Hi

Could you show a screenshot how the fields are displayed without any value? Which version of Kibana do you use? If you open the Dev Tools of you Browser are there any error messages in the console tab?

Many thx!  
Best,  
Matthias

---

<div class="post-metadata">

### Author: ![edbautista](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@edbautista](https://discuss.elastic.co/u/edbautista)
#### Post date: [November 20, 2020, 2:42am UTC](https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608/3 "2020-11-20T02:42:32Z")

</div>

![discuss1](https://us1.discourse-cdn.com/elastic/original/3X/2/9/29c6056a148ee1cf530d082d0e47704c24c65e6b.png)

No error messages shown in the console tab. I tried running a query in dev tools and it returned results. We are using Kibana 7.6.2.

Thank you for your reply!

---

<div class="post-metadata">

### Author: ![edbautista](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@edbautista](https://discuss.elastic.co/u/edbautista)
#### Post date: [December 10, 2020, 2:53am UTC](https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608/4 "2020-12-10T02:53:57Z")

</div>

Does anyone have a suggestion for this? 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: [January 7, 2021, 2:54am UTC](https://discuss.elastic.co/t/painless-script-for-comparing-nested-objects/255608/5 "2021-01-07T02:54:10Z")

</div>

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