# Document fields in script

**URL:** <https://discuss.elastic.co/t/document-fields-in-script/8083>\
**Category:** Elasticsearch\
**Created:** [June 13, 2012, 2:25pm UTC](https://discuss.elastic.co/t/document-fields-in-script/8083 "2012-06-13T14:25:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niklas\_Therning](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niklas_therning/32/2847_2.png) [@Niklas\_Therning](https://discuss.elastic.co/u/Niklas_Therning)\
**Post date:** [June 13, 2012, 2:25pm UTC](https://discuss.elastic.co/t/document-fields-in-script/8083/1 "2012-06-13T14:25:37Z")

</div>

Hi,

Can someone please explain what "document fields" are when it comes to  
custom\_score scripts? I have a field 'foo' with store=yes which I would  
like to base my custom score on. I also have "\_source" : {"enabled" :  
false} set. I can access the field using \_fields['foo'].value but that  
is too slow. In the docs it says " Document fields are very fast to  
access since they end up being loaded into memory" so I would like to  
use that instead but when I try doc['foo'].value I get a  
"PropertyAccessException[[Error: null pointer" error. So how can I make  
my field a "document field"?

Thanks  
/Niklas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 14, 2012, 9:35pm UTC](https://discuss.elastic.co/t/document-fields-in-script/8083/2 "2012-06-14T21:35:10Z")

</div>

Yes, using doc will cause accessing the loaded field from memory (you don't  
need to store it in this case). Not sure why you get the failure though,  
can you gist a curl repro?

On Wed, Jun 13, 2012 at 4:25 PM, Niklas Therning [niklas@therning.org](mailto:niklas@therning.org)wrote:

> Hi,
> 
> Can someone please explain what "document fields" are when it comes to  
> custom\_score scripts? I have a field 'foo' with store=yes which I would  
> like to base my custom score on. I also have "\_source" : {"enabled" :  
> false} set. I can access the field using \_fields['foo'].value but that is  
> too slow. In the docs it says " Document fields are very fast to access  
> since they end up being loaded into memory" so I would like to use that  
> instead but when I try doc['foo'].value I get a  
> "PropertyAccessException[[Error: null pointer" error. So how can I make my  
> field a "document field"?
> 
> Thanks  
> /Niklas

---

<div class="post-metadata">

**Author:** ![Niklas\_Therning](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niklas_therning/32/2847_2.png) [@Niklas\_Therning](https://discuss.elastic.co/u/Niklas_Therning)\
**Post date:** [June 15, 2012, 8:09am UTC](https://discuss.elastic.co/t/document-fields-in-script/8083/3 "2012-06-15T08:09:00Z")

</div>

I had index="no" on the field. Changing it to "not\_analyzed" did the trick.

On 2012-06-14 23:35, Shay Banon wrote:

> Yes, using doc will cause accessing the loaded field from memory (you  
> don't need to store it in this case). Not sure why you get the failure  
> though, can you gist a curl repro?
> 
> On Wed, Jun 13, 2012 at 4:25 PM, Niklas Therning \<[niklas@therning.org](mailto:niklas@therning.org)  
> [mailto:niklas@therning.org](mailto:niklas@therning.org)\> wrote:
> 
> ```
> Hi,
> 
> Can someone please explain what "document fields" are when it
> comes to custom_score scripts? I have a field 'foo' with store=yes
> which I would like to base my custom score on. I also have
> "_source" : {"enabled" : false} set. I can access the field using
> _fields['foo'].value but that is too slow. In the docs it says "
> Document fields are very fast to access since they end up being
> loaded into memory" so I would like to use that instead but when I
> try doc['foo'].value I get a "PropertyAccessException[[Error: null
> pointer" error. So how can I make my field a "document field"?
> 
> Thanks
> /Niklas
> 
> ```

---

<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 6, 2017, 3:23am UTC](https://discuss.elastic.co/t/document-fields-in-script/8083/4 "2017-07-06T03:23:59Z")

</div>


