Function_score with decay functions and script score

Hey guys,

I'm looking to build this complex function_score:
function_score: {
functions: [
{
script_score: {
params: {
origin : 1000000
, scale : 1000000
, offset : 1000000
, decay : 0.5
},
script: "( (doc['stats.views'].value >= offset) ? 1 : (
Math.max(0, ((scale/(1-decay)) - Math.abs(doc['stats.views'].value -
origin)) / (scale/(1-decay))) ) )"
}
},
{
script_score: {
params: {
origin : 100
, scale : 100
, offset : 100
, decay : 0.5
},
script: "( (doc['stats.likes'].value >= offset) ? 1 : (
Math.max(0, ((scale/(1-decay)) - Math.abs(doc['stats. likes'].value -
origin)) / (scale/(1-decay))) ) )"
}
},
{
exp: {
'date.published': {
origin : new Date()
, scale : '50d'
, offset : 0
, decay : 0.5
}
}
},
],
boost_mode: 'sum',
query: {
query_string: {
fields : ['title^6', 'description^3', '_text']
, query : q
}
},
score_mode: 'multiply'
}

I replaced 2 decay functions by scripts scores, because I want these to be
equal to 1 before a threshold.

Few questions:

  1. I'm not seeing the result changing with my scripts scores parameters
  2. I'm not sure when / if I have to use "_score" in the scripts
  3. Am I right using the boost_mode = 'sum'?

Thank you for your help,
Philmod

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ba8c997d-2838-493e-9f7c-6fad3d0a4b24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  1. Hard to tell, I'd probably just start simple with one function first and
    debug from there.
  2. You can use _score if you want to access the current computed score for
    the document based on your query_string query. If you want to override that
    score, then you don't need _score
  3. boost_mode='sum' means whatever score comes out of your functions will
    be added to the computed score for the document based on your query_string
    query.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/557afbc6-4cd3-4ab2-ab0b-c14d713b878e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thank you!

What I want is a multiplication of these 4 results/functions:

  • query_string * exp(date.published) * script_score(stats.views) *
    scripts_score(stats.embeds)*

And I want the last 3 to be independent of the query_string.

Any help are very welcome!

Thanks a ton,
Philippe

On Wednesday, 12 March 2014 06:41:46 UTC-7, Binh Ly wrote:

  1. Hard to tell, I'd probably just start simple with one function first
    and debug from there.
  2. You can use _score if you want to access the current computed score for
    the document based on your query_string query. If you want to override that
    score, then you don't need _score
  3. boost_mode='sum' means whatever score comes out of your functions will
    be added to the computed score for the document based on your query_string
    query.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/be3ebdcb-1d3b-43bd-aa38-0a203d4f5fc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thank you!

What I want is a multiplication of these 4 results/functions:

  • query_string * exp(date.published) * script_score(stats.views) *
    scripts_score(stats.likes)*

And I want the last 3 to be independent of the query_string.

Any help are very welcome!

Thanks a ton,
Philippe

On Wednesday, 12 March 2014 06:41:46 UTC-7, Binh Ly wrote:

  1. Hard to tell, I'd probably just start simple with one function first
    and debug from there.
  2. You can use _score if you want to access the current computed score for
    the document based on your query_string query. If you want to override that
    score, then you don't need _score
  3. boost_mode='sum' means whatever score comes out of your functions will
    be added to the computed score for the document based on your query_string
    query.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b5a2e479-cb39-46f3-bac4-7c5c4c716d70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I've had a lot of luck stuffing script scores into the rescore. It helps
if one the scripts is slower then you'd like. You do have to rely on the
query string being "pretty good" at finding the results that you want
though. Since all you want is to multiply you can do it by using a rescore
in score_mode: multiply. Like this:

rescore: {

  "window_size" : 1000,

  "query" : {
     "score_mode": "multiply",

     "rescore_query" : {
        "function_score" : {

           "script_score": {
              "script": "log10(doc['numeric'].value + 2)"

           },

                   more scripts here

        }

     }
  }

}

On Wed, Mar 12, 2014 at 1:25 PM, Philippe Modard
philippe.modard@gmail.comwrote:

Thank you!

What I want is a multiplication of these 4 results/functions:

  • query_string * exp(date.published) * script_score(stats.views) *
    scripts_score(stats.likes)*

And I want the last 3 to be independent of the query_string.

Any help are very welcome!

Thanks a ton,
Philippe

On Wednesday, 12 March 2014 06:41:46 UTC-7, Binh Ly wrote:

  1. Hard to tell, I'd probably just start simple with one function first
    and debug from there.
  2. You can use _score if you want to access the current computed score
    for the document based on your query_string query. If you want to override
    that score, then you don't need _score
  3. boost_mode='sum' means whatever score comes out of your functions will
    be added to the computed score for the document based on your query_string
    query.

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/b5a2e479-cb39-46f3-bac4-7c5c4c716d70%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/b5a2e479-cb39-46f3-bac4-7c5c4c716d70%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd1xaUupcvCkfX4Jh2kX%3DqTdS%2B4d1i---iA%3D4_BvTB7gNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

I found the issue:

I was using some javascript "Math.max" "Math.abs".

It totally works using "max()", "abs()".
And I changed the boost_mode = 'multiply' to get the result I wanted.

Thanks all,
Philmod

On Tuesday, 11 March 2014 19:03:56 UTC-7, Philippe Modard wrote:

Hey guys,

I'm looking to build this complex function_score:
function_score: {
functions: [
{
script_score: {
params: {
origin : 1000000
, scale : 1000000
, offset : 1000000
, decay : 0.5
},
script: "( (doc['stats.views'].value >= offset) ? 1 : (
Math.max(0, ((scale/(1-decay)) - Math.abs(doc['stats.views'].value -
origin)) / (scale/(1-decay))) ) )"
}
},
{
script_score: {
params: {
origin : 100
, scale : 100
, offset : 100
, decay : 0.5
},
script: "( (doc['stats.likes'].value >= offset) ? 1 : (
Math.max(0, ((scale/(1-decay)) - Math.abs(doc['stats. likes'].value -
origin)) / (scale/(1-decay))) ) )"
}
},
{
exp: {
'date.published': {
origin : new Date()
, scale : '50d'
, offset : 0
, decay : 0.5
}
}
},
],
boost_mode: 'sum',
query: {
query_string: {
fields : ['title^6', 'description^3', '_text']
, query : q
}
},
score_mode: 'multiply'
}

I replaced 2 decay functions by scripts scores, because I want these to be
equal to 1 before a threshold.

Few questions:

  1. I'm not seeing the result changing with my scripts scores parameters
  2. I'm not sure when / if I have to use "_score" in the scripts
  3. Am I right using the boost_mode = 'sum'?

Thank you for your help,
Philmod

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/dfd05f83-f531-4fd6-a2cd-0fa3dac94f1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.