Lens visualisation: bar chart breakdown of object values returns wrong count (mapping problem?)

Hello,

I would like to produce a rather simple bar chart that shows, for elements in a term aggregation, a unique count of one field in the aggregated objects that is then broken down according to a count of a different field within that same object structure.

As a first, the trivial case (unique count of ids, without breakdown) surely works, see screenshot below.

But when I add the breakdown, the amount of types appear correct but their count is not – the count of each is the same as the first id count of above, as seen below.

The relevant fields are structured like like this:

"templates": [
  {
    "name": "etyhet",
    "id": "5bc0npETZn"
  },
  {
    "name": "werwefrew",
    "id": "crqYR3X76e"
  },
  {
    "name": "fwer",
    "id": "fEqeUoodQa"
  }
]

And the mapping of those fields is as follows:

"templates": {
  "properties": {
    "id": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }
  }
}

Could the problem be the mapping, that the array of objects is flattened into independent arrays of those objects' fields? I did try the 'nested' data type but that results in Lens not knowing anything about those objects' inner fields, and the intended visualization cannot be achieved that way.
Is it possible at all, and if so how?

Any leads would be very appreciated!

Best regards,
Christian

if you enable "group by this field first" on the break down, does it give you results you expect?

"Group by this field first" merely changes the ordering on the X-axis, sorting (in this case) by 'type' instead of 'id'. The wrong counting remains...

I see now. The templates field is a nested field. Sorry I missed that before. Unfortunately right now Kibana does not work with nested fields in most of the UI-driven visualization editors (you could use them in a custom visualization, but there's a learning curve there)

You could also model the data into a specific index (or transform it) to get the data in a flattened format that would enable this in the visualization editors.

It's a very popular enhancement to add more broad support in all the places we can in Kibana in the future. Nested field support · Issue #1084 · elastic/kibana · GitHub

Thank you Graham for the clarification!
Custom visualization means Vega, or completely self made (e.g. D3)?
I guess for now I will go the route of transforming the data – that's a great hint, thanks again!

Vega where you can control the querying and how it maps to the visualization specification directly.

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