# Native Script Help

**URL:** <https://discuss.elastic.co/t/native-script-help/4467>\
**Category:** Elasticsearch\
**Created:** [May 24, 2011, 5:34pm UTC](https://discuss.elastic.co/t/native-script-help/4467 "2011-05-24T17:34:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [May 24, 2011, 5:34pm UTC](https://discuss.elastic.co/t/native-script-help/4467/1 "2011-05-24T17:34:52Z")

</div>

Hi,

I have created a NativeScriptFactory: [https://gist.github.com/989192](https://gist.github.com/989192)

Which I call using this snippet, which builds on an existing query  
that works fine: [https://gist.github.com/989184](https://gist.github.com/989184)

But this is the error I get in the response: [https://gist.github.com/989204](https://gist.github.com/989204)

This is my config where I associate the Factory with the name "my":

> <https://gist.github.com/dav-rob/989204>

Any reason why I am getting the error?

Regards,

David.

---

<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:** [May 24, 2011, 6:13pm UTC](https://discuss.elastic.co/t/native-script-help/4467/2 "2011-05-24T18:13:11Z")

</div>

You need to set the "lang" on the query builder to "native". Also, you probably want to use the docs lookup to fetch the field (all values loaded and cached to memory), compared with fields lookup, which fetches it if it was stored from the index storage.  
On Tuesday, May 24, 2011 at 8:34 PM, davrob2 wrote:

> Hi,
> 
> I have created a NativeScriptFactory: [NativeScriptFactory · GitHub](https://gist.github.com/989192)
> 
> Which I call using this snippet, which builds on an existing query  
> that works fine: [AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> But this is the error I get in the response: [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> This is my config where I associate the Factory with the name "my":  
> [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> Any reason why I am getting the error?
> 
> Regards,
> 
> David.

---

<div class="post-metadata">

**Author:** ![Paul\_Loy](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Paul\_Loy](https://discuss.elastic.co/u/Paul_Loy)\
**Post date:** [May 24, 2011, 6:14pm UTC](https://discuss.elastic.co/t/native-script-help/4467/3 "2011-05-24T18:14:23Z")

</div>

Sorry, the config link is wrong. You posted the same link as the response  
link.

On Tue, May 24, 2011 at 6:34 PM, davrob2 [daviroberts@gmail.com](mailto:daviroberts@gmail.com) wrote:

> Hi,
> 
> I have created a NativeScriptFactory: [NativeScriptFactory · GitHub](https://gist.github.com/989192)
> 
> Which I call using this snippet, which builds on an existing query  
> that works fine: [AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> But this is the error I get in the response:  
> [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> This is my config where I associate the Factory with the name "my":  
> [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> Any reason why I am getting the error?
> 
> Regards,
> 
> David.

## --

Paul Loy  
[paul@keteracel.com](mailto:paul@keteracel.com)  
[http://uk.linkedin.com/in/paulloy](http://uk.linkedin.com/in/paulloy)

---

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [May 24, 2011, 6:47pm UTC](https://discuss.elastic.co/t/native-script-help/4467/4 "2011-05-24T18:47:51Z")

</div>

Apologies, this is the config link: [script-config.yml · GitHub](https://gist.github.com/989191)

On May 24, 7:14 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:

> Sorry, the config link is wrong. You posted the same link as the response  
> link.
> 
> On Tue, May 24, 2011 at 6:34 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> 
> > Hi,
> 
> > I have created a NativeScriptFactory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)
> 
> > Which I call using this snippet, which builds on an existing query  
> > that works fine:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> > But this is the error I get in the response:  
> > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > This is my config where I associate the Factory with the name "my":  
> > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > Any reason why I am getting the error?
> 
> > Regards,
> 
> > David.
> 
> ## --
> 
> Paul Loy  
> p...@keteracel.comhttp://uk.linkedin.com/in/paulloy

---

<div class="post-metadata">

**Author:** ![Paul\_Loy](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Paul\_Loy](https://discuss.elastic.co/u/Paul_Loy)\
**Post date:** [May 24, 2011, 7:06pm UTC](https://discuss.elastic.co/t/native-script-help/4467/5 "2011-05-24T19:06:43Z")

</div>

Shay was right, you also need a

script.native.my.lang: native

On Tue, May 24, 2011 at 7:47 PM, davrob2 [daviroberts@gmail.com](mailto:daviroberts@gmail.com) wrote:

> Apologies, this is the config link: [script-config.yml · GitHub](https://gist.github.com/989191)
> 
> On May 24, 7:14 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> 
> > Sorry, the config link is wrong. You posted the same link as the response  
> > link.
> > 
> > On Tue, May 24, 2011 at 6:34 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > 
> > > Hi,
> > 
> > > I have created a NativeScriptFactory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)
> > 
> > > Which I call using this snippet, which builds on an existing query  
> > > that works fine:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> > 
> > > But this is the error I get in the response:  
> > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> > 
> > > This is my config where I associate the Factory with the name "my":  
> > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> > 
> > > Any reason why I am getting the error?
> > 
> > > Regards,
> > 
> > > David.
> > 
> > ## --
> > 
> > Paul Loy  
> > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy

## --

Paul Loy  
[paul@keteracel.com](mailto:paul@keteracel.com)  
[http://uk.linkedin.com/in/paulloy](http://uk.linkedin.com/in/paulloy)

---

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [May 24, 2011, 8:05pm UTC](https://discuss.elastic.co/t/native-script-help/4467/6 "2011-05-24T20:05:16Z")

</div>

Ok thanks for the help guys, I'm now getting a different exception  
(ClassCastException[org.elasticsearch.search.lookup.FieldLookup cannot  
be cast to java.lang.String]).

Response Error: [sortQueryResponse.json · GitHub](https://gist.github.com/989204)  
Factory: [NativeScriptFactory · GitHub](https://gist.github.com/989192)  
Config: [script-config.yml · GitHub](https://gist.github.com/989191) - both the client node and  
the servier node have this, the server node includes the needed jars  
in its classpath.  
Query Builder: [AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)

Regards,

David.

On May 24, 8:06 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:

> Shay was right, you also need a
> 
> script.native.my.lang: native
> 
> On Tue, May 24, 2011 at 7:47 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> 
> > Apologies, this is the config link:[script-config.yml · GitHub](https://gist.github.com/989191)
> 
> > On May 24, 7:14 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> > 
> > > Sorry, the config link is wrong. You posted the same link as the response  
> > > link.
> 
> > > On Tue, May 24, 2011 at 6:34 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > > 
> > > > Hi,
> 
> > > > I have created a NativeScriptFactory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)
> 
> > > > Which I call using this snippet, which builds on an existing query  
> > > > that works fine:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> > > > But this is the error I get in the response:  
> > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > > > This is my config where I associate the Factory with the name "my":  
> > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > > > Any reason why I am getting the error?
> 
> > > > Regards,
> 
> > > > David.
> 
> > > ## --
> > > 
> > > Paul Loy  
> > > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy
> 
> ## --
> 
> Paul Loy  
> p...@keteracel.comhttp://uk.linkedin.com/in/paulloy

---

<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:** [May 24, 2011, 8:10pm UTC](https://discuss.elastic.co/t/native-script-help/4467/7 "2011-05-24T20:10:01Z")

</div>

Call either DocLookup#field or DocLookup#numeric (for numeric fields), you get back the correct class to work with.  
On Tuesday, May 24, 2011 at 11:05 PM, davrob2 wrote:

> Ok thanks for the help guys, I'm now getting a different exception  
> (ClassCastException[org.elasticsearch.search.lookup.FieldLookup cannot  
> be cast to java.lang.String]).
> 
> Response Error: [sortQueryResponse.json · GitHub](https://gist.github.com/989204)  
> Factory: [NativeScriptFactory · GitHub](https://gist.github.com/989192)  
> Config: [script-config.yml · GitHub](https://gist.github.com/989191) - both the client node and  
> the servier node have this, the server node includes the needed jars  
> in its classpath.  
> Query Builder: [AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> Regards,
> 
> David.
> 
> On May 24, 8:06 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> 
> > Shay was right, you also need a
> > 
> > script.native.my.lang: native
> > 
> > On Tue, May 24, 2011 at 7:47 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > 
> > > Apologies, this is the config link:[script-config.yml · GitHub](https://gist.github.com/989191)
> > 
> > > On May 24, 7:14 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> > > 
> > > > Sorry, the config link is wrong. You posted the same link as the response  
> > > > link.
> > 
> > > > On Tue, May 24, 2011 at 6:34 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > > > 
> > > > > Hi,
> > 
> > > > > I have created a NativeScriptFactory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)
> > 
> > > > > Which I call using this snippet, which builds on an existing query  
> > > > > that works fine:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> > 
> > > > > But this is the error I get in the response:  
> > > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> > 
> > > > > This is my config where I associate the Factory with the name "my":  
> > > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> > 
> > > > > Any reason why I am getting the error?
> > 
> > > > > Regards,
> > 
> > > > > David.
> > 
> > > > ## --
> > > > 
> > > > Paul Loy  
> > > > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy
> > 
> > ## --
> > 
> > Paul Loy  
> > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy

---

<div class="post-metadata">

**Author:** ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)\
**Post date:** [July 8, 2011, 6:28am UTC](https://discuss.elastic.co/t/native-script-help/4467/8 "2011-07-08T06:28:11Z")

</div>

Hi. I know this issue is resolved. But can somebody tell me what  
DocLookup#field means?  
Actually I am having same error and could not find any solution other  
than this.

Regards.

On May 25, 1:10 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Call either DocLookup#field or DocLookup#numeric (for numeric fields), you get back the correct class to work with.
> 
> On Tuesday, May 24, 2011 at 11:05 PM, davrob2 wrote:
> 
> > Ok thanks for the help guys, I'm now getting a different exception  
> > (ClassCastException[org.elasticsearch.search.lookup.FieldLookup cannot  
> > be cast to java.lang.String]).
> 
> > Response Error:[sortQueryResponse.json · GitHub](https://gist.github.com/989204)  
> > Factory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)  
> > Config:[https://gist.github.com/989191-](https://gist.github.com/989191-) both the client node and  
> > the servier node have this, the server node includes the needed jars  
> > in its classpath.  
> > Query Builder:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> > Regards,
> 
> > David.
> 
> > On May 24, 8:06 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> > 
> > > Shay was right, you also need a
> 
> > > script.native.my.lang: native
> 
> > > On Tue, May 24, 2011 at 7:47 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > > 
> > > > Apologies, this is the config link:[script-config.yml · GitHub](https://gist.github.com/989191)
> 
> > > > On May 24, 7:14 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> > > > 
> > > > > Sorry, the config link is wrong. You posted the same link as the response  
> > > > > link.
> 
> > > > > On Tue, May 24, 2011 at 6:34 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > > > > 
> > > > > > Hi,
> 
> > > > > > I have created a NativeScriptFactory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)
> 
> > > > > > Which I call using this snippet, which builds on an existing query  
> > > > > > that works fine:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> > > > > > But this is the error I get in the response:  
> > > > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > > > > > This is my config where I associate the Factory with the name "my":  
> > > > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > > > > > Any reason why I am getting the error?
> 
> > > > > > Regards,
> 
> > > > > > David.
> 
> > > > > ## --
> > > > > 
> > > > > Paul Loy  
> > > > > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy
> 
> > > ## --
> > > 
> > > Paul Loy  
> > > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy

---

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [July 14, 2011, 4:10pm UTC](https://discuss.elastic.co/t/native-script-help/4467/9 "2011-07-14T16:10:07Z")

</div>

This is what I ended up doing:

```
                     DocLookup doc = doc();
		 StringDocFieldData custAttField = doc.field("cusAttrIdValue");
		 String custAttrsStr = custAttField.getStringValue();

```

"cusAttrIdValue" is a non-analysed String field in my mapping.

David

On Jul 8, 7:28 am, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com) wrote:

> Hi. I know this issue is resolved. But can somebody tell me what  
> DocLookup#field means?  
> Actually I am having same error and could not find any solution other  
> than this.
> 
> Regards.
> 
> On May 25, 1:10 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Call either DocLookup#field or DocLookup#numeric (for numeric fields), you get back the correct class to work with.
> 
> > On Tuesday, May 24, 2011 at 11:05 PM, davrob2 wrote:
> > 
> > > Ok thanks for the help guys, I'm now getting a different exception  
> > > (ClassCastException[org.elasticsearch.search.lookup.FieldLookup cannot  
> > > be cast to java.lang.String]).
> 
> > > Response Error:[sortQueryResponse.json · GitHub](https://gist.github.com/989204)  
> > > Factory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)  
> > > Config:[https://gist.github.com/989191-both](https://gist.github.com/989191-both) the client node and  
> > > the servier node have this, the server node includes the needed jars  
> > > in its classpath.  
> > > Query Builder:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> > > Regards,
> 
> > > David.
> 
> > > On May 24, 8:06 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> > > 
> > > > Shay was right, you also need a
> 
> > > > script.native.my.lang: native
> 
> > > > On Tue, May 24, 2011 at 7:47 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > > > 
> > > > > Apologies, this is the config link:[script-config.yml · GitHub](https://gist.github.com/989191)
> 
> > > > > On May 24, 7:14 pm, Paul Loy [ketera...@gmail.com](mailto:ketera...@gmail.com) wrote:
> > > > > 
> > > > > > Sorry, the config link is wrong. You posted the same link as the response  
> > > > > > link.
> 
> > > > > > On Tue, May 24, 2011 at 6:34 PM, davrob2 [davirobe...@gmail.com](mailto:davirobe...@gmail.com) wrote:
> > > > > > 
> > > > > > > Hi,
> 
> > > > > > > I have created a NativeScriptFactory:[NativeScriptFactory · GitHub](https://gist.github.com/989192)
> 
> > > > > > > Which I call using this snippet, which builds on an existing query  
> > > > > > > that works fine:[AddScriptSort\_snippet · GitHub](https://gist.github.com/989184)
> 
> > > > > > > But this is the error I get in the response:  
> > > > > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > > > > > > This is my config where I associate the Factory with the name "my":  
> > > > > > > [sortQueryResponse.json · GitHub](https://gist.github.com/989204)
> 
> > > > > > > Any reason why I am getting the error?
> 
> > > > > > > Regards,
> 
> > > > > > > David.
> 
> > > > > > ## --
> > > > > > 
> > > > > > Paul Loy  
> > > > > > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy
> 
> > > > ## --
> > > > 
> > > > Paul Loy  
> > > > p...@keteracel.comhttp://uk.linkedin.com/in/paulloy

---

<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, 4:00am UTC](https://discuss.elastic.co/t/native-script-help/4467/10 "2017-07-06T04:00:37Z")

</div>


