Bar chart - Aggregate by Field1 or Field2

I have documents with 2 fields that I would like to use for aggregation.
The document will look something like

"_source" : {
          "name" : "name_value",
          "id" : "id_value",

But, some names might be missing/empty.

I would like to show a bar chart (For example) that shows count by name, but if the name is empty present the id instead.

Is this possible? How?
If not, any alternatives?