How to add two value from two type?


(Saurab Dahal) #1

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 ?


(Alexander Reelsen) #2

Not sure I follow this requirement exactly. You might want to take a look at the update API.


(Saurab Dahal) #3

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?


(Alexander Reelsen) #4

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.


(Saurab Dahal) #5

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


(Alexander Reelsen) #6

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


(Saurab Dahal) #7

oh, thanks :slight_smile:


(system) #8

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