Problem using the custom score query with a script

Hello everyone,

I tried to make a script and use it to calculate my own score but it does
not act like it should be.
Here is my script:

time = (param14 - doc['creationDate'].value) / 86400; // 1 day = 86400sec
score = doc['timesViewed'].value *
param1 +
doc['timesOlogized'].value

  • param3 +
    doc['timesCommented'].value
  • param2 +
    (doc['timesLoved'].value +
    doc['timesHated'].value +
    doc['timesHmm'].value) *
    param4 +
    (doc['timesFacebook'].value
  • doc['timesTwitter'].value +
    doc['timesTumblr'].value +
    doc['timesPinterest'].value +

doc['timesGoogleplus'].value + doc['timesReddit'].value) * param5;
if (time > 365){
score * param13 * _score;
}
else if (time > 279){
score * param12 * _score;
}
else if (time > 186){
score * param11 * _score;
}
else if (time > 93){
score * param10 * _score;
}
else if (time > 31){
score * param9 * _score;
}
else if (time > 7){
score * param8 * _score;
}
else if (time > 1){
score * param7 * _score;
}
else {
score * param6 * _score;
}
With the following parameters:
array(
'param1' => self::SCORE_NB_POST_VIEWS,
'param2' => self::SCORE_NB_POST_COMMENTED,
'param3' => self::SCORE_NB_POST_OLOGIZED,
'param4' => self::SCORE_NB_POST_LIKE,
'param5' => self::SCORE_NB_EXTERNAL_SHARES,
'param6' => self::TM_POST_TODAY,
'param7' => self::TM_POST_THIS_WEEK,
'param8' => self::TM_POST_THIS_MONTH,
'param9' => self::TM_POST_THREE_MONTH,
'param10' => self::TM_POST_SIX_MONTH,
'param11' => self::TM_POST_NINE_MONTH,
'param12' => self::TM_POST_THIS_YEAR,
'param13' => self::TM_POST_OLDER_YEAR,
'param14' => $this->today
)
Apparently $time is not set as it should be because it seems to go in the
last else each time!
$time should be the number of days since the document has been created with
creationDate the creation timestamp and param14 is the actual timestamp
calculate with time() (PHP). I also tried to return score at the end but
it did not change anything...

Is there something wrong in my script? How can I test it? Is there a way to
print variable?
Thank you for your help!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

I typically test such scripts one step at a time using script_field.
script_field makes it much easier to see what's getting returned for each
record. You can print from the screen to stdout using
System.out.println(....) but this is only useful if you run elasticsearch
locally in foreground mode. Alternatively, you can write messages into the
log file using this somewhat convoluted
call: org.elasticsearch.common.logging.Loggers.getLogger("my_logger").info("message
from the script");

On Thursday, April 18, 2013 4:16:47 PM UTC-4, Damien wrote:

Hello everyone,

I tried to make a script and use it to calculate my own score but it does
not act like it should be.
Here is my script:

time = (param14 - doc['creationDate'].value) / 86400; // 1 day = 86400sec
score = doc['timesViewed'].value *
param1 +
doc['timesOlogized'].value

  • param3 +

doc['timesCommented'].value * param2 +
(doc['timesLoved'].value +
doc['timesHated'].value +
doc['timesHmm'].value) *
param4 +

(doc['timesFacebook'].value + doc['timesTwitter'].value +
doc['timesTumblr'].value +
doc['timesPinterest'].value +

doc['timesGoogleplus'].value + doc['timesReddit'].value) * param5;
if (time > 365){
score * param13 * _score;
}
else if (time > 279){
score * param12 * _score;
}
else if (time > 186){
score * param11 * _score;
}
else if (time > 93){
score * param10 * _score;
}
else if (time > 31){
score * param9 * _score;
}
else if (time > 7){
score * param8 * _score;
}
else if (time > 1){
score * param7 * _score;
}
else {
score * param6 * _score;
}
With the following parameters:
array(
'param1' => self::SCORE_NB_POST_VIEWS,
'param2' => self::SCORE_NB_POST_COMMENTED,
'param3' => self::SCORE_NB_POST_OLOGIZED,
'param4' => self::SCORE_NB_POST_LIKE,
'param5' => self::SCORE_NB_EXTERNAL_SHARES,
'param6' => self::TM_POST_TODAY,
'param7' => self::TM_POST_THIS_WEEK,
'param8' => self::TM_POST_THIS_MONTH,
'param9' => self::TM_POST_THREE_MONTH,
'param10' => self::TM_POST_SIX_MONTH,
'param11' => self::TM_POST_NINE_MONTH,
'param12' => self::TM_POST_THIS_YEAR,
'param13' => self::TM_POST_OLDER_YEAR,
'param14' => $this->today
)
Apparently $time is not set as it should be because it seems to go in the
last else each time!
$time should be the number of days since the document has been created
with creationDate the creation timestamp and param14 is the actual
timestamp calculate with time() (PHP). I also tried to return score at the
end but it did not change anything...

Is there something wrong in my script? How can I test it? Is there a way
to print variable?
Thank you for your help!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Yeah log file is better than nothing. Thanks for the line but I'm using
elasticsearch in PHP environment and I'm not sure there is log system like
in Java.
So I don't know how to call getLogger()... I'm going to search how to call
it now.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

It will be logged in the elasticsearch log file. Here is a complete
example: https://github.com/imotov/elasticsearch-test-scripts/blob/master/logging_from_script.sh

On Thursday, April 18, 2013 5:14:16 PM UTC-4, Damien wrote:

Yeah log file is better than nothing. Thanks for the line but I'm using
elasticsearch in PHP environment and I'm not sure there is log system like
in Java.
So I don't know how to call getLogger()... I'm going to search how to call
it now.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

It seems to work, I mean there is no error when executing the script.
Now I just have to find where is this log file if it actually worked.
Thanks again.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Try this:

curl -s "elasticsearch_address:9200/_nodes/_local?settings=true&pretty=true"
| grep "path.logs"

On Thursday, April 18, 2013 5:48:28 PM UTC-4, Damien wrote:

It seems to work, I mean there is no error when executing the script.
Now I just have to find where is this log file if it actually worked.
Thanks again.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Perfect! Found it, thanks.
But apparently, that does not print something in the log file. I just found
the exact same line with the logger call...

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Apparently, MVEL is getting confused if it gets no parameters in the info
requests. I have updated the
example: https://github.com/imotov/elasticsearch-test-scripts/blob/master/logging_from_script.sh
It should work now

On Thursday, April 18, 2013 6:09:57 PM UTC-4, Damien wrote:

Perfect! Found it, thanks.
But apparently, that does not print something in the log file. I just
found the exact same line with the logger call...

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Yes! It works thank you. I can see now that my time variable is null each
time. Apparently you cannot use the word 'time' as a variable, it might be
a key word for MVEL. I just changed the name time in timeModifier and it
works. This would have been impossible to figure it out without log. Thanks!

Le jeudi 18 avril 2013 18:24:37 UTC-4, Igor Motov a écrit :

Apparently, MVEL is getting confused if it gets no parameters in the info
requests. I have updated the example:
https://github.com/imotov/elasticsearch-test-scripts/blob/master/logging_from_script.shIt should work now

On Thursday, April 18, 2013 6:09:57 PM UTC-4, Damien wrote:

Perfect! Found it, thanks.
But apparently, that does not print something in the log file. I just
found the exact same line with the logger call...

--
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.
For more options, visit https://groups.google.com/groups/opt_out.