Subtracting 2 fields different document on Scripted Field / json input

I have a set of data below.

I want to add the red marker then subtract it to the blue marker.
I tried using Scripted Field.

But when I go back to discovery I have this error.

If I will put it on the line graph I want to subtract the blue line from the green line to see the difference on the data.

Hello @rikizita3

It looks like you need to perform calculations across data. The best way to address this would be to get both fields into the same document. How are you ingesting your data?