# Scripts - is it possible to write a 2 phase script?

**URL:** <https://discuss.elastic.co/t/scripts-is-it-possible-to-write-a-2-phase-script/45456>\
**Category:** Elasticsearch\
**Created:** [March 25, 2016, 3:20pm UTC](https://discuss.elastic.co/t/scripts-is-it-possible-to-write-a-2-phase-script/45456 "2016-03-25T15:20:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karol\_Stojek](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@Karol\_Stojek](https://discuss.elastic.co/u/Karol_Stojek)\
**Post date:** [March 25, 2016, 3:20pm UTC](https://discuss.elastic.co/t/scripts-is-it-possible-to-write-a-2-phase-script/45456/1 "2016-03-25T15:20:56Z")

</div>

I need 2 queries to find the data I want:

1. full text search on a field
2. if there are entries found - extract token from another field (probably using regexp)
3. perform additional query - filter the data by the token extracted in step 2.

so the output of first query should be the input to a second filter.  
Is it possible to write that kind of script?

---

<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:** [July 5, 2017, 11:05pm UTC](https://discuss.elastic.co/t/scripts-is-it-possible-to-write-a-2-phase-script/45456/2 "2017-07-05T23:05:09Z")

</div>

Closed on July 5, 2017, 11:05pm UTC


