# Native custom script performance: stored fields

**URL:** <https://discuss.elastic.co/t/native-custom-script-performance-stored-fields/12496>\
**Category:** Elasticsearch\
**Created:** [June 20, 2013, 3:09pm UTC](https://discuss.elastic.co/t/native-custom-script-performance-stored-fields/12496 "2013-06-20T15:09:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maciej\_Kula](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Maciej\_Kula](https://discuss.elastic.co/u/Maciej_Kula)\
**Post date:** [June 20, 2013, 3:09pm UTC](https://discuss.elastic.co/t/native-custom-script-performance-stored-fields/12496/1 "2013-06-20T15:09:19Z")

</div>

Hello,

I'm trying to use a CustomScore query to score documents based on a  
function of several of their fields, and am looking to optimize its  
performance.

I am using a native (Java) custom score script, which accesses several  
document fields, all of which are indexed (but not stored).

When profiling the code using VisualVM, I see that most of the time taken  
by the query is spent in

1. org.elasticsearch.search.lookup.DocLookup.get() --- I am retrieving  
several text fields
2. 

org.elasticsearch.search.index.fieldData.ScriptDocValues$Doubles.getValues()  
--- I am retrieving an array of doubles

Is the speed at which the above complete affected by the stored property on  
those fields? In general, what is the fastest way of accessing document  
fields in native scripts?

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [June 21, 2013, 7:16am UTC](https://discuss.elastic.co/t/native-custom-script-performance-stored-fields/12496/2 "2013-06-21T07:16:03Z")

</div>

Hi,

On Thu, Jun 20, 2013 at 5:09 PM, Maciej Kula [aggregaccount@gmail.com](mailto:aggregaccount@gmail.com)wrote:

> Is the speed at which the above complete affected by the stored property  
> on those fields? In general, what is the fastest way of accessing document  
> fields in native scripts?

Performance is unrelated to the stored property of your fields. The fastest  
way to access document fields in native scripts is through the doc()  
method, but given that you see DocLookup.get in your profiles, it looks  
like this is what you are already doing.

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Maciej\_Kula](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Maciej\_Kula](https://discuss.elastic.co/u/Maciej_Kula)\
**Post date:** [June 21, 2013, 9:51am UTC](https://discuss.elastic.co/t/native-custom-script-performance-stored-fields/12496/3 "2013-06-21T09:51:56Z")

</div>

Thank you. That's really useful.

Maciej

On Friday, June 21, 2013 8:16:03 AM UTC+1, Adrien Grand wrote:

> Hi,
> 
> On Thu, Jun 20, 2013 at 5:09 PM, Maciej Kula \<[aggreg...@gmail.com](mailto:aggreg...@gmail.com)\<javascript:\>
> 
> > wrote:
> > 
> > Is the speed at which the above complete affected by the stored property  
> > on those fields? In general, what is the fastest way of accessing document  
> > fields in native scripts?
> 
> Performance is unrelated to the stored property of your fields. The  
> fastest way to access document fields in native scripts is through the  
> doc() method, but given that you see DocLookup.get in your profiles, it  
> looks like this is what you are already doing.
> 
> --  
> Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:30am UTC](https://discuss.elastic.co/t/native-custom-script-performance-stored-fields/12496/4 "2017-07-06T02:30:02Z")

</div>


