Divide Sums with conditions an d group by

Hi,
I have documents that looks like

{
  ...
  "_source": {
	...
    "Number_2": 64,
	...
    "Name_A": "RANDOM_A",
	...
    "Number_1": 4,
	...
    "Name_B": "RANDOM_B"
  },

I would like to show a ratio calculation of the following

x = sum(number_1) group by name_a
y = sum(number_2) group by name_a
calculate x/y

so each value will be summed once, as unique. Then show it on a graph or a metric.
Eventually, use this metric in a ML job.

Example
Number_1 values = 4,4,8,8,16,32,32,32,32
Number_2 values = 64,64

(4+4+8+8+16+32+32+32+32)/(64+64) = 168/128 = 0.76

How is that possible?
I did a few tries and errors, but they all fail.

Thanks!