OpenSearch - Sum Amount from array grouped by key

242 Views Asked by At

I want to create an Table Visualization in OpenSearch which sums the amount of diffrenz items grouped by the hash of the item.

The raw data looks like:

{
  "_source": {
    "fieldH": "example",
    "items": [
      {
        "hash": "item1",
        "amount": 2
      },
      {
        "hash": "item2",
        "amount": 3
      }
    ],
    "date": "2023-01-20T11:08:35.960Z"
  }
}
{
  "_source": {
    "fieldH": "example",
    "items": [
      {
        "hash": "item2",
        "amount": 5
      },
      {
        "hash": "item3",
        "amount": 3
      }
    ],
    "date": "2023-01-20T11:08:35.960Z"
  }
}

currently it looks like: (bcs it sums all amounts which are in the found document)

Item Hash Amount
Item1 5
Item2 13
Item3 8

The result should look like:

Item Hash Amount
Item1 2
Item2 8
Item3 3

Visualisation Settings Looks like: enter image description here enter image description here

Does somebody knows how to handle this?

0

There are 0 best solutions below