How do I read basic fields and apply them to a mark using Vega? (not vega-lite)

Hi everyone,

We have a requirement to build a custom Vega visualisation, and I've read the Vega and Vega-Lite documentation on github through and through. I understand how to create amazing looking dashboards with it now, but I cannot find any Elastic documentation that goes into detail on how to build the data query object to pull basic fields from an index and do a basic "sum of values" on them.

My use-case... I have data that looks like this:

{
    "_index": "myindex",
    "_type": "doc",
    "_id": "abc123",
    "_version": 1,
    "_score": null,
    "timestamp": "2022-05-23T07:43:21.123Z",
    "_source": {
        "fruit": [{
                "amount": 15,
                "type": {
                    "grower_id": 47,
                    "grower_country": "US",
                    "name": "apple"
                }
            },
            {
                "amount": 43,
                "type": {
                    "grower_id": 47,
                    "grower_country": "CAN",
                    "name": "apple"
                }
            },
            {
                "amount": 7,
                "type": {
                    "grower_id": 23,
                    "grower_country": "US",
                    "name": "orange"
                }
            },
            {
                "amount": 14,
                "type": {
                    "grower_id": 23,
                    "grower_country": "CAN",
                    "name": "orange"
                }
            }
        ]
    }
}

And what I want to do is put 2 symbol marks on a visualisation, 1 for Apples and 1 for Oranges. I want to turn these widgets red, amber or green based on the sum of all the "amount" field for each. I already know how to do the symbol marks and the signal scales to change their color, but what I cannot for the life of me figure out is how to define the data object to pull out and sum the "amount" fields from each, let alone also split the values based on whether they are for "apples" vs "oranges".

All of the documentation starts out by saying "Vega" but as soon as I get to any form of example, it's actually in Vega-Lite, which is not entirely the same and I would rather not go down a path that later limits my options. Also the only examples given are purely for doing a simple doc_count in time buckets, not for the summing of values in fields etc.

Can anyone please help me to find out how to achieve this? Where is the Vega documentation or information on how to form the data object?

Thanks.

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