Need some input/advice on scripting approach

Hello - I am an elasticsearch newbie and after doing a lot of reading, I
think I need to use scripts to accomplish my objectives. Basically, we are
indexing and searching documents already, and now we need to do a
non-trivial financial calculation based on user-provided inputs. The
output of the calculation depends on the users inputs, and he output of the
calculation will be a field in the results (a script_field ?) as well as
used to filter/query the results (a filter script?).

#1) I'd like to have the same script/function be used for the script_field
and the filter script to avoid code duplication - is this possible?

#2 ) Do I need to install my script inside elasticsearch (rather than pass
it in my query) in order to achieve this?

It seems like that would be better for performance as well, which leads me
to my next question:

#3) Should I write the script in Java for performance reasons? I have no
experience with MVEL, and I know Java already - is Java faster than MVEL
for number crunching?

Thanks in advance for any advice you might have!

Greg

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ab8e3d97-4d89-4f2e-bcbe-7fca5ee66a7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

On Thu, Apr 3, 2014 at 4:07 PM, Greg Lappen greg@lapcominc.com wrote:

Hello - I am an elasticsearch newbie and after doing a lot of reading, I
think I need to use scripts to accomplish my objectives. Basically, we are
indexing and searching documents already, and now we need to do a
non-trivial financial calculation based on user-provided inputs. The
output of the calculation depends on the users inputs, and he output of the
calculation will be a field in the results (a script_field ?) as well as
used to filter/query the results (a filter script?).

#1) I'd like to have the same script/function be used for the script_field
and the filter script to avoid code duplication - is this possible?

I don't know.

#2 ) Do I need to install my script inside elasticsearch (rather than pass
it in my query) in order to achieve this?

Not if you write it in MVEL or some other scripting language for which you
have installed a plugin.

It seems like that would be better for performance as well, which leads me
to my next question:

#3) Should I write the script in Java for performance reasons? I have no
experience with MVEL, and I know Java already - is Java faster than MVEL
for number crunching?

Java is faster but I'd advise trying it with MVEL first anyway. MVEL is
like Java except I never trust the order of operations so that shouldn't be
a problem. Its much faster to prototype it and you may find that the
ability to change it without restarting Elasticsearch is worth the speed
difference.

One things to keep in mind: if you really really want it to be fast you
should try to lean on Lucene as much as possible. Script filters have to
examine every document but term and range filters use the lucene index to
chop out huge swaths of documents at a time. They can also be cached
really easily making them even quicker. So what I'm saying is if you can
limit the documents you actually run the script filter against it'll be
quicker.

Thanks in advance for any advice you might have!

Greg

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ab8e3d97-4d89-4f2e-bcbe-7fca5ee66a7f%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/ab8e3d97-4d89-4f2e-bcbe-7fca5ee66a7f%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3sBPimWk2NED0gyC-NZ%2BKL%3DSPu4Y_b%3Dm_ORwWo1T7fFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

For #1, if you define a native script in Java, yes the code can be shared
between script_fields and script filter. It's also possible to define an
MVEL script in a file that you put inside the config/scripts folder but it
might be hassle to maintain if you have lots of nodes.

Other questions, Nikolas is right.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1d8df8cd-09dc-4d71-84ed-b1364e326bb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.