# Questions about scripted\_field and painless

**URL:** <https://discuss.elastic.co/t/questions-about-scripted-field-and-painless/73374>\
**Category:** Elasticsearch\
**Created:** [January 31, 2017, 1:53pm UTC](https://discuss.elastic.co/t/questions-about-scripted-field-and-painless/73374 "2017-01-31T13:53:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blocka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blocka/32/15061_2.png) [@blocka](https://discuss.elastic.co/u/blocka)\
**Post date:** [January 31, 2017, 1:53pm UTC](https://discuss.elastic.co/t/questions-about-scripted-field-and-painless/73374/1 "2017-01-31T13:53:56Z")

</div>

My first question: Can a scripted\_field be used for searching?  
Assuming it can, are there performance issues with that?

Does the ArrayList object have `Map` method (like `Array.prototype.map` in javascript)?

I have lift of Gifts stored with in index, and I want to use a scripted\_field to get the total amount over a given period.

I've started with this:

`int total = 0; for (def gift : ctx._source.Gifts) { total+=gift.Amount} return total`

But I keep keep getting a null reference exception. Same thing when I tried without the ctx

---

<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:** [February 28, 2017, 1:54pm UTC](https://discuss.elastic.co/t/questions-about-scripted-field-and-painless/73374/2 "2017-02-28T13:54:01Z")

</div>

Closed on February 28, 2017, 1:54pm UTC

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