Native Script Field

Hi,

I've implemented script based sorting using native Java Classes but
I'm new to this for script based fields. Can someone give some some
pointers on how to do this.

  • David.

Or, to put it another way, am I restricted to defining my scripted
field in MVEL or can I use Java to perform my functions on other
fields, at runtime, to produce the scripted fields?

On Sep 6, 5:41 pm, davrob2 davirobe...@gmail.com wrote:

Hi,

I've implemented script based sorting using native Java Classes but
I'm new to this for script based fields. Can someone give some some
pointers on how to do this.

  • David.

You can use Java to perform your functions. Other than that, the question is
not really focused, so hard to answer...

On Wed, Sep 7, 2011 at 1:53 PM, davrob2 daviroberts@gmail.com wrote:

Or, to put it another way, am I restricted to defining my scripted
field in MVEL or can I use Java to perform my functions on other
fields, at runtime, to produce the scripted fields?

On Sep 6, 5:41 pm, davrob2 davirobe...@gmail.com wrote:

Hi,

I've implemented script based sorting using native Java Classes but
I'm new to this for script based fields. Can someone give some some
pointers on how to do this.

  • David.

Thanks for the reply Shay.

I have been confused by what sort of ExecutableScript to return in my
NativeScript factory but I think things are clearing up now. This is
what my take on the process is now:

If I want to return a string, rather than a float for sorting, then I
just need to extend AbstractSearchScript and overide the run()
method. Ideally, I should use doc() to look up values most
efficiently, or use fields() if Ihave defined an "addFields()" method
in my SearchRequest, the source() method should only be used if I
can't get the value I want any other way.

Additionally, is it possible to sort on scripted fields? If so, would
I need a custom sort to do that, or would Elasticsearch detect the
return type ( e.g. Date ) from a custom field and be able to sort it
out-of-the box.

  • David

On Sep 7, 4:51 pm, Shay Banon kim...@gmail.com wrote:

You can use Java to perform your functions. Other than that, the question is
not really focused, so hard to answer...

On Wed, Sep 7, 2011 at 1:53 PM, davrob2 davirobe...@gmail.com wrote:

Or, to put it another way, am I restricted to defining my scripted
field in MVEL or can I use Java to perform my functions on other
fields, at runtime, to produce the scripted fields?

On Sep 6, 5:41 pm, davrob2 davirobe...@gmail.com wrote:

Hi,

I've implemented script based sorting using native Java Classes but
I'm new to this for script based fields. Can someone give some some
pointers on how to do this.

  • David.

On Thu, Sep 8, 2011 at 11:57 AM, davrob2 daviroberts@gmail.com wrote:

Thanks for the reply Shay.

I have been confused by what sort of ExecutableScript to return in my
NativeScript factory but I think things are clearing up now. This is
what my take on the process is now:

If I want to return a string, rather than a float for sorting, then I
just need to extend AbstractSearchScript and overide the run()
method. Ideally, I should use doc() to look up values most
efficiently, or use fields() if Ihave defined an "addFields()" method
in my SearchRequest, the source() method should only be used if I
can't get the value I want any other way.

Accessing fields is expensive as well, it simply fetches it from stored
fields. Note, even if you defined fields to be "fetched" (which might be
stored), they are only extracted for the "size" docs you ask for, not across
all hits matching the query (which your script probably do, depends where
you use it).

Additionally, is it possible to sort on scripted fields? If so, would
I need a custom sort to do that, or would Elasticsearch detect the
return type ( e.g. Date ) from a custom field and be able to sort it
out-of-the box.

For custom script sorting, you define what type base to do sorting, it can
be either numeric or a string.

  • David

On Sep 7, 4:51 pm, Shay Banon kim...@gmail.com wrote:

You can use Java to perform your functions. Other than that, the question
is
not really focused, so hard to answer...

On Wed, Sep 7, 2011 at 1:53 PM, davrob2 davirobe...@gmail.com wrote:

Or, to put it another way, am I restricted to defining my scripted
field in MVEL or can I use Java to perform my functions on other
fields, at runtime, to produce the scripted fields?

On Sep 6, 5:41 pm, davrob2 davirobe...@gmail.com wrote:

Hi,

I've implemented script based sorting using native Java Classes but
I'm new to this for script based fields. Can someone give some some
pointers on how to do this.

  • David.