# How to discount index who change from a Transform

**URL:** https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449
**Category:** Elasticsearch
**Tags:** transforms
**Created:** [January 18, 2023, 7:21pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449 "2023-01-18T19:21:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![solrac97gr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/solrac97gr/32/116109_2.png) [@solrac97gr](https://discuss.elastic.co/u/solrac97gr)
#### Post date: [January 18, 2023, 7:21pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/1 "2023-01-18T19:21:09Z")

</div>

I have a specific task and we decided to solved it using transform

- Our Case:  
We need to count and aggregate by status a index  
like this

```auto
 {
      created_at: "2023-01-15"
      accepted:10,
      review: 15,
   }

```

One register for every day.

We reach this using the Transform the problem is we can update the status of the transactions but looks like the Transform is not discounting from the past information only adding when the field we conditioned is modify (updated\_at)

There is some way for also discount from the past counts.

---

<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: [January 19, 2023, 6:58am UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/2 "2023-01-19T06:58:23Z")

</div>

> [@solrac97gr](#):
>
> There is some way for also discount from the past counts.

Can you explain how a "discount" is implemented in the source index? How do the documents look like that you ingest? It would also help if you can share relevant parts of the transform config.

---

<div class="post-metadata">

### Author: ![solrac97gr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/solrac97gr/32/116109_2.png) [@solrac97gr](https://discuss.elastic.co/u/solrac97gr)
#### Post date: [January 19, 2023, 7:45pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/3 "2023-01-19T19:45:21Z")

</div>

We have a specific problem, a group of transactions and their status can change on the time for example past from "on review" to "accepted" so we calculate a transform who counts this status for all transactions.

Our problem is when we update one status for example "on review" past to be "accepted" the transform update the row of count in "accepted" but don't discount -1 to the row of "on review"

---

<div class="post-metadata">

### Author: ![solrac97gr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/solrac97gr/32/116109_2.png) [@solrac97gr](https://discuss.elastic.co/u/solrac97gr)
#### Post date: [January 19, 2023, 7:58pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/4 "2023-01-19T19:58:00Z")

</div>

![Screenshot 2023-01-19 at 13.56.39](https://us1.discourse-cdn.com/elastic/original/3X/9/b/9bbaab8c436d1fddfee7d37194f7049a429a3ea0.png)  
 ![Screenshot 2023-01-19 at 13.57.08](https://us1.discourse-cdn.com/elastic/original/3X/1/1/11de730480841add40b90eb94030487b411e1d25.png)

Here is some Screens of the configuration for my transform

---

<div class="post-metadata">

### Author: ![solrac97gr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/solrac97gr/32/116109_2.png) [@solrac97gr](https://discuss.elastic.co/u/solrac97gr)
#### Post date: [January 19, 2023, 8:03pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/5 "2023-01-19T20:03:05Z")

</div>

This is how looks my index after I start the transform

 ![Screenshot 2023-01-19 at 13.58.39](https://us1.discourse-cdn.com/elastic/original/3X/f/1/f1f9d3da10459c9ab2616b8e3d467abc1f7dc5e6.png)  
And after Update the status of the review transaction to "success" it increase one to success but not reduce the count in review.  
 ![Screenshot 2023-01-19 at 14.01.27](https://us1.discourse-cdn.com/elastic/original/3X/f/f/fff8e4d2773043ee2abc1065781379758df66c80.png)

---

<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: [January 23, 2023, 4:34pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/6 "2023-01-23T16:34:34Z")

</div>

> [@solrac97gr](#):
>
> Our problem is when we update one status for example "on review" past to be "accepted" the transform update the row of count in "accepted" but don't discount -1 to the row of "on review"

Does `accepted` _always_ contain `review`?  
If I get it right, you want to deduct `accepted` from `review`. You can do this using an ingest pipeline that you attach to the transform output. In the ingest pipeline I would set `review` to `review - accepted`, e.g. using a [script processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/script-processor.html).

Another alternative I can think of is using a [runtime field](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html) that you specify on the transform destination.

---

<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: [February 20, 2023, 4:34pm UTC](https://discuss.elastic.co/t/how-to-discount-index-who-change-from-a-transform/323449/7 "2023-02-20T16:34:39Z")

</div>

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