How to get average of items in an array of a nested field?

And a related problem...by adding properties.inventory.type: "nested" to the mapping, kibana lens can no longer access any of the inventory.* fields. I posted the problem as a separate question here: