# Using Painless Scripted Field

**URL:** <https://discuss.elastic.co/t/using-painless-scripted-field/108328>\
**Category:** Kibana\
**Created:** [November 20, 2017, 7:32am UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328 "2017-11-20T07:32:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanshandy](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@seanshandy](https://discuss.elastic.co/u/seanshandy)\
**Post date:** [November 20, 2017, 7:32am UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/1 "2017-11-20T07:32:02Z")

</div>

I have some question about using scripted field with painless, so i have some set of data that look like this,  
One Document can only contain identifier (MWStart or MWEnd), and i want to get like:  
if the identifier is MWStart then find the reqtxnid that the identifier is MWEnd. so how can i do dis?

 ![asd](https://us1.discourse-cdn.com/elastic/original/3X/b/f/bf39101aa60589e28d6ed6e159da9671b6960474.png)

and i have tried this script:

> string reqTXNID = doc['reqtxnid.keyword'].value;  
> string idf = doc['identifier.keyword'].value;
> 
> if(idf == 'MWStart') {  
> for(int i=0; i\<params.\_source.reqtxnid.length; i++) {  
> if(params.\_source.reqtxnid[i] == reqTXNID && params.\_source.identifier[i] == "MWEnd"){  
> return 1;  
> break;  
> }  
> else { return 0;}  
> }  
> }  
> else {return null;}

then i got this error:

> Discover: compile error [script] Too many dynamic script compilations within one minute, max: [15/min]; please use on-disk, indexed, or scripts with parameters instead; this limit can be changed by the [script.max\_compilations\_per\_minute] setting

i hope someone can help me 😭 , thanks

---

<div class="post-metadata">

**Author:** ![seanshandy](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@seanshandy](https://discuss.elastic.co/u/seanshandy)\
**Post date:** [November 20, 2017, 7:46am UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/3 "2017-11-20T07:46:55Z")

</div>

sorry if the previous script is unclear, this is the repost for the script:

![qwe](https://us1.discourse-cdn.com/elastic/original/3X/1/4/1447b834f683d549e8b71a459a8631d2f7a3abcf.png)

and the result that i wanted should be look like this:

 ![asd](https://us1.discourse-cdn.com/elastic/original/3X/d/3/d3031b97b574454b75d5a8d67f99201789728ab5.png)

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [November 20, 2017, 7:56pm UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/4 "2017-11-20T19:56:58Z")

</div>

A scripted field only has access to a single document at a time. You seem to be under the mistaken impression that you can access the entire result set. There isn't a way to do what you are trying to do at query time. You may want to index the data so that each document contains both the start and end data.

Hope this helps.

Cheers  
Rashmi

---

<div class="post-metadata">

**Author:** ![seanshandy](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@seanshandy](https://discuss.elastic.co/u/seanshandy)\
**Post date:** [November 21, 2017, 3:21am UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/5 "2017-11-21T03:21:42Z")

</div>

Oh i see rashmi, thanks. But then how can i index the data that can contains both start and end data while the source contain only one data? i really cant think the way to achieve this

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [November 21, 2017, 8:10pm UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/6 "2017-11-21T20:10:29Z")

</div>

You could create "entity-centric" indices. This page might help [https://www.elastic.co/videos/entity-centric-indexing-mark-harwood](https://www.elastic.co/videos/entity-centric-indexing-mark-harwood)

Thanks  
Rashmi

---

<div class="post-metadata">

**Author:** ![seanshandy](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@seanshandy](https://discuss.elastic.co/u/seanshandy)\
**Post date:** [November 23, 2017, 3:41am UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/7 "2017-11-23T03:41:06Z")

</div>

oke ill try it rashmi, thanks!

---

<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:** [December 21, 2017, 3:41am UTC](https://discuss.elastic.co/t/using-painless-scripted-field/108328/8 "2017-12-21T03:41:56Z")

</div>

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