Elasticsearch Match columns from different indexes with condition

I have 2 different indexes in elasticsearch, indx1

and indx2

which I indexed from SQL database using river plugin.

 indx1

----------
    id  |  Amt
    1      2
    2      3
    3      2   
    1      9 
    2      4 
----------

      

indx 2

----------
id   |  Name 
1       Alex
2       Joe
3       MARY


----------

      

I want to create a new index that calculates the average from indx1

and combines everything in one index. So the final index structure should look like

indx_final


----------
id | Name | Avg Amt | Status
1    Alex    5.5      High
2    Joe     3.5      Med
3    Mary    2.0      Low
----------

      

The status is set in accordance with the average value if Avg amt> 4, status = high, if avg amt> 3, status = Med, if avg amt <2.5, status = Low. Can this only be done in elasticsearch? If this is not possible, I will have to do the calculations in SQL and then index the data again.

Any help would be greatly appreciated. Thank!

+3


source to share





All Articles