# Substract 2 fields from different indexes and plot on Kibana

**URL:** https://discuss.elastic.co/t/substract-2-fields-from-different-indexes-and-plot-on-kibana/286572
**Category:** Kibana
**Created:** [October 13, 2021, 6:24am UTC](https://discuss.elastic.co/t/substract-2-fields-from-different-indexes-and-plot-on-kibana/286572 "2021-10-13T06:24:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pr1yadarshan](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pr1yadarshan](https://discuss.elastic.co/u/pr1yadarshan)
#### Post date: [October 13, 2021, 6:24am UTC](https://discuss.elastic.co/t/substract-2-fields-from-different-indexes-and-plot-on-kibana/286572/1 "2021-10-13T06:24:34Z")

</div>

I have 2 indexes (sys-1-logs, sys-2-logs), I want to get the difference of count of both and plot on Kibana. Is this possible to do ? If yes then how to do it ?

---

<div class="post-metadata">

### Author: ![Mustafa\_NAJIB](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mustafa_najib/32/95797_2.png) [@Mustafa\_NAJIB](https://discuss.elastic.co/u/Mustafa_NAJIB)
#### Post date: [October 13, 2021, 10:00am UTC](https://discuss.elastic.co/t/substract-2-fields-from-different-indexes-and-plot-on-kibana/286572/2 "2021-10-13T10:00:35Z")

</div>

Hello,

I think that you have to use the Timelion visualisation in Kibana  
i'll show you an example that you can test in your environnement.  
i'm using as time field "TIMESTAMP" , according to your case you can use the timefield which matches with your indexes

**Timelion expression**

```auto
.es(index=sys-1-logs,
    timefield='TIMESTAMP',
    q='message:*')
    .subtract(.es(index=sys-2-logs,
             timefield='TIMESTAMP', 
              q='message:*' )
             .legend(columns=2, position=nw))
             .title('Sub of counts')

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/4/a45dfaf171318c9ca9b5b5bcd407337045dd5af3.png)

---

<div class="post-metadata">

### Author: ![pr1yadarshan](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pr1yadarshan](https://discuss.elastic.co/u/pr1yadarshan)
#### Post date: [October 18, 2021, 11:02am UTC](https://discuss.elastic.co/t/substract-2-fields-from-different-indexes-and-plot-on-kibana/286572/3 "2021-10-18T11:02:35Z")

</div>

> [@Mustafa\_NAJIB](#):
>
> ```auto
> .es(index=sys-1-logs,
> timefield='TIMESTAMP',
> q='message:*')
> .subtract(.es(index=sys-2-logs,
> timefield='TIMESTAMP', 
> q='message:*' )
> .legend(columns=2, position=nw))
> .title('Sub of counts')
> 
> ```

Thanks a lot, it worked !!

---

<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: [November 15, 2021, 11:02am UTC](https://discuss.elastic.co/t/substract-2-fields-from-different-indexes-and-plot-on-kibana/286572/4 "2021-11-15T11:02:42Z")

</div>

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