It seems that under normal search conditions, that calling doc().score()
from a Java script will result in an uncaught exception (since the scorer
is null).
For instance, a simple query on the twitter example data:
'{ "query": {"text": {"message":"elastic"}}, "script_fields": {}}
The above executes without an error until I attempt to access the score.
When handling the exception myself, the '_score' and 'max_score' fields
have the expected values in the response.
The script_field is executed during fetch phase when scorer is not longer
used (it already performed its function during search phase). But why do
you need score in the script_field?
On Tuesday, November 27, 2012 5:17:55 PM UTC-5, Ryan Hill wrote:
It seems that under normal search conditions, that calling doc().score()
from a Java script will result in an uncaught exception (since the scorer
is null).
For instance, a simple query on the twitter example data:
'{ "query": {"text": {"message":"elastic"}}, "script_fields": {}}
The above executes without an error until I attempt to access the score.
When handling the exception myself, the '_score' and 'max_score' fields
have the expected values in the response.
Sorry for resurrecting an old thread, but we currently have exactly the
same issue. In a Java script derived from Abstract*SearchScript, we need to
calculate a field based on (among other things) the score as calculated by
ES.
I understand that the scorer is null because it's no longer needed, but
isn't there any other way to get the score that was calculated by it
earlier?
Thanks
Klaus
On Thursday, 29 November 2012 01:04:36 UTC+1, Igor Motov wrote:
The script_field is executed during fetch phase when scorer is not longer
used (it already performed its function during search phase). But why do
you need score in the script_field?
On Tuesday, November 27, 2012 5:17:55 PM UTC-5, Ryan Hill wrote:
It seems that under normal search conditions, that calling doc().score()
from a Java script will result in an uncaught exception (since the scorer
is null).
Rather than calling doc().score() try calling score().
-Eric
On Tuesday, January 29, 2013 4:43:05 AM UTC-5, Klaus Brunner wrote:
Sorry for resurrecting an old thread, but we currently have exactly the
same issue. In a Java script derived from Abstract*SearchScript, we need to
calculate a field based on (among other things) the score as calculated by
ES.
I understand that the scorer is null because it's no longer needed, but
isn't there any other way to get the score that was calculated by it
earlier?
Thanks
Klaus
On Thursday, 29 November 2012 01:04:36 UTC+1, Igor Motov wrote:
The script_field is executed during fetch phase when scorer is not longer
used (it already performed its function during search phase). But why do
you need score in the script_field?
On Tuesday, November 27, 2012 5:17:55 PM UTC-5, Ryan Hill wrote:
It seems that under normal search conditions, that calling doc().score()
from a Java script will result in an uncaught exception (since the scorer
is null).
On Tuesday, 29 January 2013 15:05:02 UTC+1, egaumer wrote:
Rather than calling doc().score() try calling score().
We did. It's NaN, just the way the score field is initialised in
AbstractSearchScript. Seems it's never touched. (We also set
track_scores=true, to make sure, even though we don't use sorting.)
The query works and goes through. The script is called and works fine,
except when we want it to read the score. We also tried switching
explanations on and off, no effect.
This is on 0.20.2, but from earlier testing 0.19.7 showed the same
behaviour.
Seems like this only works if you're using a CustomScoreQuery (which I am).
You should try wrapping your current query.
On Tuesday, January 29, 2013 9:38:44 AM UTC-5, Klaus Brunner wrote:
On Tuesday, 29 January 2013 15:05:02 UTC+1, egaumer wrote:
Rather than calling doc().score() try calling score().
We did. It's NaN, just the way the score field is initialised in
AbstractSearchScript. Seems it's never touched. (We also set
track_scores=true, to make sure, even though we don't use sorting.)
The query works and goes through. The script is called and works fine,
except when we want it to read the score. We also tried switching
explanations on and off, no effect.
This is on 0.20.2, but from earlier testing 0.19.7 showed the same
behaviour.
Seems like this only works if you're using a CustomScoreQuery (which I
am). You should try wrapping your current query.
We're using a script_field, just like the OP.
The problem is that we don't want to change the score, but to set a new
field based on the score and other stuff. This doesn't seem to work from a
CustomScoreQuery, but from a script_field it does. However, it seems that
the score is never set when running a script as part of a script_field...
So, actually I'm looking for either
a way to get the score in a Java script called from a script_field, or
a way to set a field from a Java script called from a CustomScoreQuery.
After some digging in the code, it seems that our application will
definitely require a CustomScoreQuery: we're calculating a new score based
on the "original" score and some other stuff. And it makes sense to
actually sort on this new score.
However, we still need a way to get at the original score from the query
wrapped by the CustomScoreQuery. My best guess so far is using the explain
option, but that seems like overkill: we don't need the detailed info on
all queries below, and it seems that explain will slow things down
significantly. All we need is that one additional "original score" field
for each returned hit.
Are there any other clever ideas on getting this value out?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.