Scripted Field for sum of max value!

I would like to write the script that need to show "Sum of Max value" .

For example,

Here, you can see same IP has opened two session and view the page.The value is accumulated [incremental] one. So I have to take max value of each session and sum the output.

Hence, I will get an exact and total amount used per IP.

How can I implement this in scripted field in kibana4

Not sure you can at the moment.
Pipeline aggs should help once they have been implemented.