# Loop over same field in documents in scripted fields

**URL:** <https://discuss.elastic.co/t/loop-over-same-field-in-documents-in-scripted-fields/167087>\
**Category:** Kibana\
**Created:** [February 5, 2019, 9:23am UTC](https://discuss.elastic.co/t/loop-over-same-field-in-documents-in-scripted-fields/167087 "2019-02-05T09:23:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedwe](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@fedwe](https://discuss.elastic.co/u/fedwe)\
**Post date:** [February 5, 2019, 9:23am UTC](https://discuss.elastic.co/t/loop-over-same-field-in-documents-in-scripted-fields/167087/1 "2019-02-05T09:23:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 5, 2019, 9:40am UTC](https://discuss.elastic.co/t/loop-over-same-field-in-documents-in-scripted-fields/167087/2 "2019-02-05T09:40:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fedwe](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@fedwe](https://discuss.elastic.co/u/fedwe)\
**Post date:** [February 6, 2019, 8:35am UTC](https://discuss.elastic.co/t/loop-over-same-field-in-documents-in-scripted-fields/167087/3 "2019-02-06T08:35:08Z")

</div>

is there another way to work this around like referencing them

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 6, 2019, 8:35am UTC](https://discuss.elastic.co/t/loop-over-same-field-in-documents-in-scripted-fields/167087/4 "2019-03-06T08:35:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
