# Scripted field for same month data

**URL:** https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121
**Category:** Elasticsearch
**Created:** [November 20, 2020, 12:56pm UTC](https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121 "2020-11-20T12:56:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)
#### Post date: [November 20, 2020, 12:56pm UTC](https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121/1 "2020-11-20T12:56:23Z")

</div>

Hi All,

We are trying to build a dashboard for a new scenario,like we are ingesting data from servicenow using logstash, the data has ticket information like opened and closed, we want to build a dashboard for monthly backlog tickets, which is tickets opened and not closed on the same month.

Trying to writing a scripted field to identify this, but not able to, can someone guide me how can i achieve this.

**logic we are trying is, if "created month" and "closed month" are same then return 0 else return 1**

Thanks  
Gautham

---

<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: [November 20, 2020, 2:08pm UTC](https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121/2 "2020-11-20T14:08:38Z")

</div>

Are the fields part of the _same_ or _different_ documents?

---

<div class="post-metadata">

### Author: ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)
#### Post date: [November 20, 2020, 2:31pm UTC](https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121/3 "2020-11-20T14:31:26Z")

</div>

@Hendrik_Muhs Fields are from same documents.

---

<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: [November 20, 2020, 2:57pm UTC](https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121/4 "2020-11-20T14:57:34Z")

</div>

You can use a `script` as part of the aggregation you are looking for, e.g. [`sum`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html#_script_15). The script is applied per data point, therefore if you return 1 if and only if your criteria is met you get the total count the criteria was met. Vice versa you can create another sum aggregation with reversed logic.

---

<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: [December 18, 2020, 2:57pm UTC](https://discuss.elastic.co/t/scripted-field-for-same-month-data/256121/5 "2020-12-18T14:57:40Z")

</div>

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