Difference between two aggregations

Hi all

I am looking for some help with a watcher that I am trying to run. Basically I am trying to run a search query that will return a value if there is a difference between two aggregations.

Below is the script I am running in dev tools to compare the cardinality of number of documents in 15 min intervals to the cumulative cardinality of number of documents over a 1 hour period. I only want the script to output for differences between the two values and at the moment it is outputting regardless of whether there is a difference of not;

</>
{
"script_fields": {
"bucket_script": {
"script": {
"lang": "painless",
"source": """

int i = params._source.aggregations.book_name.buckets[0].pull_tag.buckets[0].per_15m.buckets[0].total_docs.value;
int j = params._source.aggregations.book_name.buckets[0].pull_tag.buckets[0].per_15m.buckets[0].card.value;

if ( i != j )
{
return params._source.aggregations.host_name.buckets[0].key
}

"""
}
}
}
}
</>