# How to add two value from two type?

**URL:** <https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652>\
**Category:** Elasticsearch\
**Created:** [August 19, 2017, 8:00am UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652 "2017-08-19T08:00:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurab\_Dahal](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Saurab\_Dahal](https://discuss.elastic.co/u/Saurab_Dahal)\
**Post date:** [August 19, 2017, 8:00am UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/1 "2017-08-19T08:00:25Z")

</div>

For example, I have this structure  
`index/type1` which has `item1 with mrp 20` like this `{"item":"item1","mrp"20}`  
and on second type `index/type2` which has `item1 with mrp 10` like this `{"item":"item1","mrp"20}`.  
Now I need to add mrp of that item. which should be total of 40. Is it possible with elaticsearch ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 19, 2017, 1:27pm UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/2 "2017-08-19T13:27:09Z")

</div>

Not sure I follow this requirement exactly. You might want to take a look at the [update API](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/docs-update.html).

---

<div class="post-metadata">

**Author:** ![Saurab\_Dahal](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Saurab\_Dahal](https://discuss.elastic.co/u/Saurab_Dahal)\
**Post date:** [August 19, 2017, 1:47pm UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/3 "2017-08-19T13:47:18Z")

</div>

Thankyou for the link, that was helpful. What I wanted to know is , consider this SQL  
`select sum(mrp) from table1 join table2 where item="apple"`, just an example. Can this be achieved from ES?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 20, 2017, 9:17pm UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/4 "2017-08-20T21:17:55Z")

</div>

you can do this with aggregations, search both indices, run a terms aggregation on the item and then have a sub aggregation, which sums up the `mrp` field.

---

<div class="post-metadata">

**Author:** ![Saurab\_Dahal](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Saurab\_Dahal](https://discuss.elastic.co/u/Saurab_Dahal)\
**Post date:** [August 21, 2017, 4:11am UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/5 "2017-08-21T04:11:44Z")

</div>

Sorry, but I have not become an expert yet 🙂 . How do I search two indices at the same time ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 21, 2017, 10:52am UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/6 "2017-08-21T10:52:39Z")

</div>

see [https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-search.html#search-multi-index-type](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-search.html#search-multi-index-type)

---

<div class="post-metadata">

**Author:** ![Saurab\_Dahal](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Saurab\_Dahal](https://discuss.elastic.co/u/Saurab_Dahal)\
**Post date:** [August 21, 2017, 11:04am UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/7 "2017-08-21T11:04:02Z")

</div>

oh, thanks 🙂

---

<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:** [September 18, 2017, 11:04am UTC](https://discuss.elastic.co/t/how-to-add-two-value-from-two-type/97652/8 "2017-09-18T11:04:16Z")

</div>

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