# Script\_fields for document GET requests

**URL:** <https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843>\
**Category:** Elasticsearch\
**Created:** [February 29, 2012, 8:54pm UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843 "2012-02-29T20:54:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Pendleton](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Andrew\_Pendleton](https://discuss.elastic.co/u/Andrew_Pendleton)\
**Post date:** [February 29, 2012, 8:54pm UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843/1 "2012-02-29T20:54:47Z")

</div>

I noticed that the search API has both a "fields" parameter for basic field  
filtering and a "script\_fields" parameter to do it programmatically. The  
single-document GET api, though, only has "fields." Is there any  
particular reason for this? If it's not fundamentally a bad idea, how hard  
would it be to do via a plugin?

Andrew

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 1, 2012, 12:39am UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843/2 "2012-03-01T00:39:34Z")

</div>

My guess is since a GET request looks at both the index and the log  
for a document, it is not able to compute a script field for when the  
document only exists in the log. Just a guess.

--  
Ivan

On Wed, Feb 29, 2012 at 12:54 PM, Andrew Pendleton [abpend@gmail.com](mailto:abpend@gmail.com) wrote:

> I noticed that the search API has both a "fields" parameter for basic field  
> filtering and a "script\_fields" parameter to do it programmatically. The  
> single-document GET api, though, only has "fields." Is there any particular  
> reason for this? If it's not fundamentally a bad idea, how hard would it be  
> to do via a plugin?
> 
> Andrew

---

<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:** [March 1, 2012, 11:05am UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843/3 "2012-03-01T11:05:13Z")

</div>

Even if its in the transaction log, we still have access to the logs, so we can potentially support script\_fields if there is a need. Open an issue?

On Thursday, March 1, 2012 at 2:39 AM, Ivan Brusic wrote:

> My guess is since a GET request looks at both the index and the log  
> for a document, it is not able to compute a script field for when the  
> document only exists in the log. Just a guess.
> 
> --  
> Ivan
> 
> On Wed, Feb 29, 2012 at 12:54 PM, Andrew Pendleton \<[abpend@gmail.com](mailto:abpend@gmail.com) ([mailto:abpend@gmail.com](mailto:abpend@gmail.com))\> wrote:
> 
> > I noticed that the search API has both a "fields" parameter for basic field  
> > filtering and a "script\_fields" parameter to do it programmatically. The  
> > single-document GET api, though, only has "fields." Is there any particular  
> > reason for this? If it's not fundamentally a bad idea, how hard would it be  
> > to do via a plugin?
> > 
> > Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_Pendleton](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Andrew\_Pendleton](https://discuss.elastic.co/u/Andrew_Pendleton)\
**Post date:** [March 1, 2012, 3:25pm UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843/4 "2012-03-01T15:25:51Z")

</div>

Before I do: my usecase is that I have documents that contain an array  
of several objects, each of which has a large (potentially mutli-  
megabyte) text field on it, and I often want to retrieve one of these  
objects from a particular document's array without incurring the  
bandwidth expense of transferring the whole thing to the application  
server. It seems, from further experimentation after I posted the  
original message, that doing a search with an ID filter and a  
script\_field accomplishes what I was going for and is pretty fast. Do  
you think a GET with a script\_field would be faster enough (if that's  
grammatical) to be worth the bother? Or should I be thinking about  
doing this another way entirely?

Andrew

On Mar 1, 6:05 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Even if its in the transaction log, we still have access to the logs, so we can potentially support script\_fields if there is a need. Open an issue?
> 
> On Thursday, March 1, 2012 at 2:39 AM, Ivan Brusic wrote:
> 
> > My guess is since a GET request looks at both the index and the log  
> > for a document, it is not able to compute a script field for when the  
> > document only exists in the log. Just a guess.
> 
> > --  
> > Ivan
> 
> > On Wed, Feb 29, 2012 at 12:54 PM, Andrew Pendleton \<[abp...@gmail.com](mailto:abp...@gmail.com) ([mailto:abp...@gmail.com](mailto:abp...@gmail.com))\> wrote:
> > 
> > > I noticed that the search API has both a "fields" parameter for basic field  
> > > filtering and a "script\_fields" parameter to do it programmatically. The  
> > > single-document GET api, though, only has "fields." Is there any particular  
> > > reason for this? If it's not fundamentally a bad idea, how hard would it be  
> > > to do via a plugin?
> 
> > > Andrew

---

<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:** [March 3, 2012, 9:38pm UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843/5 "2012-03-03T21:38:35Z")

</div>

Yes, GET will be faster (though search will probably be fast enough), and I think the feature make sense.

On Thursday, March 1, 2012 at 5:25 PM, Andrew Pendleton wrote:

> Before I do: my usecase is that I have documents that contain an array  
> of several objects, each of which has a large (potentially mutli-  
> megabyte) text field on it, and I often want to retrieve one of these  
> objects from a particular document's array without incurring the  
> bandwidth expense of transferring the whole thing to the application  
> server. It seems, from further experimentation after I posted the  
> original message, that doing a search with an ID filter and a  
> script\_field accomplishes what I was going for and is pretty fast. Do  
> you think a GET with a script\_field would be faster enough (if that's  
> grammatical) to be worth the bother? Or should I be thinking about  
> doing this another way entirely?
> 
> Andrew
> 
> On Mar 1, 6:05 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Even if its in the transaction log, we still have access to the logs, so we can potentially support script\_fields if there is a need. Open an issue?
> > 
> > On Thursday, March 1, 2012 at 2:39 AM, Ivan Brusic wrote:
> > 
> > > My guess is since a GET request looks at both the index and the log  
> > > for a document, it is not able to compute a script field for when the  
> > > document only exists in the log. Just a guess.
> > 
> > > --  
> > > Ivan
> > 
> > > On Wed, Feb 29, 2012 at 12:54 PM, Andrew Pendleton \<[abp...@gmail.com](mailto:abp...@gmail.com) ([mailto:abp...@gmail.com](mailto:abp...@gmail.com) ([http://gmail.com](http://gmail.com)))\> wrote:
> > > 
> > > > I noticed that the search API has both a "fields" parameter for basic field  
> > > > filtering and a "script\_fields" parameter to do it programmatically. The  
> > > > single-document GET api, though, only has "fields." Is there any particular  
> > > > reason for this? If it's not fundamentally a bad idea, how hard would it be  
> > > > to do via a plugin?
> > 
> > > > Andrew

---

<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:37am UTC](https://discuss.elastic.co/t/script-fields-for-document-get-requests/6843/6 "2017-07-06T03:37:29Z")

</div>


