Mvel expression support in ES custom scoring

Hi all,

I'm trying to do a custom score function in MVEL and need to learn how to
deal with a null value (ideally, the null value would not be there of
course!) but it's already in the index now:

I want to take my existing score and let's say e.g. divide it by a
particular document field value(checkVal( if available, 1 if not

From looking at:
http://mvel.codehaus.org/MVEL+2.0+Control+Flow

I thought i could just say:
"script" : "_score * (doc['checkVal'].value==nil?1:doc['checkVal'].value)"

The problem is that documents that have a nil/null value seem to be ignored
and all others use the correct value. (the value gets used in the query
phase also - that is why i am using doc instead of source)

I've also tried null instead of null and have seen people talking about
'.?' as a value check also?

Derry

--

If checkVal had the "string" type, doc['checkVal'].value==null?... would
have worked. For a numeric type, you can do something like:

_score * (doc['checkVal'].value==0.0?1:doc['checkVal'].value)

On Wednesday, October 24, 2012 1:18:10 PM UTC-4, Derry O' Sullivan wrote:

Hi all,

I'm trying to do a custom score function in MVEL and need to learn how to
deal with a null value (ideally, the null value would not be there of
course!) but it's already in the index now:

I want to take my existing score and let's say e.g. divide it by a
particular document field value(checkVal( if available, 1 if not

From looking at:
http://mvel.codehaus.org/MVEL+2.0+Control+Flow

I thought i could just say:
"script" : "_score * (doc['checkVal'].value==nil?1:doc['checkVal'].value)"

The problem is that documents that have a nil/null value seem to be
ignored and all others use the correct value. (the value gets used in the
query phase also - that is why i am using doc instead of source)

I've also tried null instead of null and have seen people talking about
'.?' as a value check also?

Derry

--

Thanks for that - one of my fields is an numeric type so i can use the 0.0 check. For a date type, which is where the default null value? Looking at:

http://joda-time.sourceforge.net/api-release/org/joda/time/MutableDateTime.html
and

Can there be a 'default'/null date? (i'm using the standard format, not any custom one...)

On Wednesday, 24 October 2012 18:46:45 UTC+1, Igor Motov wrote:

If checkVal had the "string" type, doc['checkVal'].value==null?... would have worked. For a numeric type, you can do something like:

_score * (doc['checkVal'].value==0.0?1:doc['checkVal'].value)

On Wednesday, October 24, 2012 1:18:10 PM UTC-4, Derry O' Sullivan wrote:Hi all,

I'm trying to do a custom score function in MVEL and need to learn how to deal with a null value (ideally, the null value would not be there of course!) but it's already in the index now:

I want to take my existing score and let's say e.g. divide it by a particular document field value(checkVal( if available, 1 if not

From looking at:
http://mvel.codehaus.org/MVEL+2.0+Control+Flow

I thought i could just say:
"script" : "_score * (doc['checkVal'].value==nil?1:doc['checkVal'].value)"

The problem is that documents that have a nil/null value seem to be ignored and all others use the correct value. (the value gets used in the query phase also - that is why i am using doc instead of source)

I've also tried null instead of null and have seen people talking about '.?' as a value check also?

Derry

--

The value of a date field has type long (it's equal to UTC milliseconds
since the epoch). So, you can simply check for 0.

On Wednesday, October 24, 2012 7:30:43 PM UTC-4, Derry O' Sullivan wrote:

Thanks for that - one of my fields is an numeric type so i can use the 0.0
check. For a date type, which is where the default null value? Looking at:
Elasticsearch Platform — Find real-time answers at scale | Elastic

MutableDateTime (Joda time 2.1 API)
and
Elasticsearch Platform — Find real-time answers at scale | Elastic

Can there be a 'default'/null date? (i'm using the standard format, not
any custom one...)

On Wednesday, 24 October 2012 18:46:45 UTC+1, Igor Motov wrote:

If checkVal had the "string" type, doc['checkVal'].value==null?... would
have worked. For a numeric type, you can do something like:

_score * (doc['checkVal'].value==0.0?1:doc['checkVal'].value)

On Wednesday, October 24, 2012 1:18:10 PM UTC-4, Derry O' Sullivan
wrote:Hi all,

I'm trying to do a custom score function in MVEL and need to learn how
to deal with a null value (ideally, the null value would not be there of
course!) but it's already in the index now:

I want to take my existing score and let's say e.g. divide it by a
particular document field value(checkVal( if available, 1 if not

From looking at:
http://mvel.codehaus.org/MVEL+2.0+Control+Flow

I thought i could just say:
"script" : "_score

  • (doc['checkVal'].value==nil?1:doc['checkVal'].value)"

The problem is that documents that have a nil/null value seem to be
ignored and all others use the correct value. (the value gets used in the
query phase also - that is why i am using doc instead of source)

I've also tried null instead of null and have seen people talking about
'.?' as a value check also?

Derry

--

Many thanks Igor, that worked perfectly.

It also helped when i remembered to add that doc field in the mapping to
one of the indexes :wink:

On Thursday, 25 October 2012 00:50:54 UTC+1, Igor Motov wrote:

The value of a date field has type long (it's equal to UTC milliseconds
since the epoch). So, you can simply check for 0.

On Wednesday, October 24, 2012 7:30:43 PM UTC-4, Derry O' Sullivan wrote:

Thanks for that - one of my fields is an numeric type so i can use the
0.0 check. For a date type, which is where the default null value? Looking
at:
Elasticsearch Platform — Find real-time answers at scale | Elastic

MutableDateTime (Joda time 2.1 API)
and
Elasticsearch Platform — Find real-time answers at scale | Elastic

Can there be a 'default'/null date? (i'm using the standard format, not
any custom one...)

On Wednesday, 24 October 2012 18:46:45 UTC+1, Igor Motov wrote:

If checkVal had the "string" type, doc['checkVal'].value==null?...
would have worked. For a numeric type, you can do something like:

_score * (doc['checkVal'].value==0.0?1:doc['checkVal'].value)

On Wednesday, October 24, 2012 1:18:10 PM UTC-4, Derry O' Sullivan
wrote:Hi all,

I'm trying to do a custom score function in MVEL and need to learn how
to deal with a null value (ideally, the null value would not be there of
course!) but it's already in the index now:

I want to take my existing score and let's say e.g. divide it by a
particular document field value(checkVal( if available, 1 if not

From looking at:
http://mvel.codehaus.org/MVEL+2.0+Control+Flow

I thought i could just say:
"script" : "_score

  • (doc['checkVal'].value==nil?1:doc['checkVal'].value)"

The problem is that documents that have a nil/null value seem to be
ignored and all others use the correct value. (the value gets used in the
query phase also - that is why i am using doc instead of source)

I've also tried null instead of null and have seen people talking about
'.?' as a value check also?

Derry

--