Loop over same field in documents in scripted fields

hello, i want to make a pattern to match mobile numbers. i indexed to the same index documents that have 2 fields country code and counter name. i want to like return the country code for example

i have a field number in my documents and a value 9650122453
i want to check if 965 matches a country code in my indexed documents

Scripted fields are run in the context of a single document, so can not look across other documents.

is there another way to work this around like referencing them