Using script fileds in custom score queries


(drcivan) #1

Hi,

I have a calculated script field, similar to following example:

"script_fields" : {
"script_field" : {
"script" : "doc['my_field_name'].value * factor",
"params" : {
"factor" : 2.0
}
}
}

I want to use this script field, in my custom score query like:

"custom_score" : {
"query" : {
....
},
"script" : "script_field * 2" // ?
}

I can't refer the calculated variable as "script_field" or
"doc['script_field'].value", both are throwing errors.
Is there any way to reuse the script fields in custom scoring queries?

--


(phill) #2

No. As far as I understand "script_fields" are like "fields",
"highlight" fields, they are all created pretty much after all document
(IDs) have been rounded up. Therefore they are not something you can
refer to in a query or filter, so you can't use them as a 'macro'.

Given that, as it says on the customer score query page, you can put the
script and parameter values, as you wrote right in your query.

-Paul

On 8/30/2012 7:57 AM, drcivan wrote:

Hi,

I have a calculated script field, similar to following example:

"script_fields" : {
"script_field" : {
"script" : "doc['my_field_name'].value * factor",
"params" : {
"factor" : 2.0
}
}
}

I want to use this script field, in my custom score query like:

"custom_score" : {
"query" : {
....
},
"script" : "script_field * 2" // ?
}

I can't refer the calculated variable as "script_field" or
"doc['script_field'].value", both are throwing errors.
Is there any way to reuse the script fields in custom scoring queries?

--


(drcivan) #3

Thank you Paul. I wasn just trying to avoid the duplicate calculation
of script. But as you say, there is no other way to do it.

On 30 A─čustos, 18:12, "P.Hill" parehi...@gmail.com wrote:

No. As far as I understand "script_fields" are like "fields",
"highlight" fields, they are all created pretty much after all document
(IDs) have been rounded up. Therefore they are not something you can
refer to in a query or filter, so you can't use them as a 'macro'.

Given that, as it says on the customer score query page, you can put the
script and parameter values, as you wrote right in your query.

-Paul

On 8/30/2012 7:57 AM, drcivan wrote:

Hi,

I have a calculated script field, similar to following example:

"script_fields" : {
"script_field" : {
"script" : "doc['my_field_name'].value * factor",
"params" : {
"factor" : 2.0
}
}
}

I want to use this script field, in my custom score query like:

"custom_score" : {
"query" : {
....
},
"script" : "script_field * 2" // ?
}

I can't refer the calculated variable as "script_field" or
"doc['script_field'].value", both are throwing errors.
Is there any way to reuse the script fields in custom scoring queries?

--


(system) #4