I have three tables Customer, Product and Transactions. I have used Elastic Search to build index joining the three tables. The output of the index looks something like this
{
"customer_id": 101,
"name": "John Doe",
"transactions":
[
{
"product_id": 11,
"product_name": "T-Shirt",
"transaction_id": "TX101",
"price": "500"
},
{
"product_id": 11,
"product_name": "T-Shirt",
"transaction_id": "TX101",
"price": "600"
},
{
"product_id": 12,
"product_name": "Shirt",
"transaction_id": "TX102",
"price": "1000"
}
]
}
I would like a total_transaction field that contains sum of price from all the transactions.
Is it possible to have the field dynamically added while building the index or while retrieving the documents.
I tried the aggregates, but they work on the whole data. The aggregate functions doesnt work within each document.
I use Postgres database. If there is another way to achieve this, that would also be welcomed