'Opensearch and Vega retrieve null fields in composite aggregation

I'm using the VEGA visualization in OpenSearch to create a tree representation like this example from the documentation. Data are stored inside an index and I'm currently storing 3 fields related to this tree creation:

  • Key (string)
  • ParentKey (unique string of the parent) => equals to '-' for the root.
  • Depth (int that represent to depth in the tree from 1 to x)

Key and depth are a primary key.

Here is how I'm formatting my data

  "data": [
    {
      name: "pageviews",
      "url":{
        %context%: true,
        index: "x"
        body:{
          "aggs": {
            "treeNodes": {
              "composite": {
                "size": 5000
                "sources": [
                  {
                    "key": {
                      "terms": {
                        "field": "x.key"
                      }
                    }
                  },
                  {
                    "lvl": {
                      "terms": {
                        "field": "x.lvl"
                      }
                    }
                  },
                 {
                    "parent": {
                      "terms": {
                        "field": "x.parentKey"
                      }
                    }
                  },
                ]
              }
            }
          }
        }
      }
    "format": {property: "aggregations.treeNodes.buckets"}
    "transform": [
        {
          "type": "stratify",
          "key": "key.key",
          "parentKey": "key.parent"
        },
        {
          "type": "tree",
          "method": "tidy",
          "size": ["1600", "500"],
          "separation": false,
          "as": ["y", "x", "depth", "children"]
        }
      ]
    },
    {
        "name": "links",
        "source": "x",
        "transform": [
          { "type": "treelinks" },
          {
            "type": "linkpath",
            "orient": "horizontal",
            "shape": "line",
          }
        ]
      }
  ],

As you can see, I'm using a composite aggregation that groups unique trio (key, parentKey, lvl).

But by doing so and with the tree example I'm getting the following error

missing: -

When I checked at the data from the example I could see that root node don't have any value for parent and so my problem is that I should not put any value for the parentKey of the root.

But I can't find a way to do it :

  • If parentKey is null with my current aggregation, the value will be ignore and then I will miss the root node. So is there a way to add missing value ? I tried to do it by adding missing : null but missing seems to not be understand by composite aggregation.
  • An other and probably better solution would be to exclude the parent in my aggregation (keep key + lvl) and then add the corresponding parentKey in a column. I'm new to all of this so I don't know how to do it.

Basically what I want to do is

Select parentKey, key, lvl from x group by key,lvl  

(It looks so basic in SQL..)

Hope someone can help I'm completely stuck.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source