How to add a script_fields to score calculation?


(Sebastien Lavoie) #1

Hi,

I understand I can use a custom_scorehttp://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html with
script and that I can use script_fieldshttp://www.elasticsearch.org/guide/reference/api/search/script-fields.html to
calculate fields.

Now, what I want to do is to reuse the value generated with the
script_field to use in score calculation. The script I use is quite heavy
so I don’t really want to duplicate it.

Basically, I want something like this:

{
"query": {
"custom_score" : {
"query" : {
"match_all" : {}
},
"script" : "_score * (1 + my_complex_field * 0.2)"
}
},
"script_fields" : {
"my_complex_field" : {
"script" : "my_complex_script",
"params": {
"max_date": 1342017125,
"min_date": 1340289125
}
}
}
}

Any ideas ?

Thanks


(Sebastien Lavoie) #2

Otherwise, is it possible to define a MVEL function on a global level (or
in the index) and simply call this function everywhere ?

On Wednesday, July 11, 2012 2:01:33 PM UTC-4, Sebastien Lavoie wrote:

Hi,

I understand I can use a custom_scorehttp://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html with
script and that I can use script_fieldshttp://www.elasticsearch.org/guide/reference/api/search/script-fields.html to
calculate fields.

Now, what I want to do is to reuse the value generated with the
script_field to use in score calculation. The script I use is quite heavy
so I don’t really want to duplicate it.

Basically, I want something like this:

{
"query": {
"custom_score" : {
"query" : {
"match_all" : {}
},
"script" : "_score * (1 + my_complex_field * 0.2)"
}
},
"script_fields" : {
"my_complex_field" : {
"script" : "my_complex_script",
"params": {
"max_date": 1342017125,
"min_date": 1340289125
}
}
}
}

Any ideas ?

Thanks


(micherr) #3

Hi!

If there any updates on the subject? I`m facing the same issue.


(Sébastien Lavoie) #4

I am sorry, I was never able to make it work, I had to use it twice.

--
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.


(Alexander Reelsen) #5

Hey,

defining global scripts will not help your problem, but at least make it
easier to execute/maintain, more about that
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html

iirc it is not possible to access the script fields in your score. I am
wondering, if you cant just use the score to go on?
Also you might want to use the function_score query,
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

--Alex

On Tue, Nov 19, 2013 at 2:13 AM, Sébastien Lavoie sebastien@lavoie.slwrote:

I am sorry, I was never able to make it work, I had to use it twice.

--
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.

--
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.


(system) #6