Function Scoring

Hi
I want to search for a hotel based on distance. I would like to give boost
based on the range . Like 5 for 0-10km, 3 for 10-100km, 1 for greater than
100km .
I proceded with Function Score Query

"function_score": {
"functions": [
{

        "boost_factor": "5",
        "filter": {geo Range Filter(0-10)}
    },

    {

        "boost_factor": "3",
        "filter": {geo Range Filter(10-100)}
    },{

        "boost_factor": "1",
        "filter": {geo Range Filter(100-1000)}
    },

],
"query": {...},
"score_mode": "first"

}

I have a few questions.

  1. Does this query calculate the distance thrice for same document because
    of 3 filters? .
  2. how I use decay function to implement the same functionality?

Thank you,
Vinay

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

Hi Vinay,

the distance is indeed computed three times.
You can use a decay function to achieve a continuous decay. Below is
an example for a query that scores the docs with field value "num"
5/3/1 with score 5/3/1 and interpolates in between. Everything below 1
is scored as one. Unsure which kind of curve fits best in your case
though. Also, you would still need two range filters, one for the
documents that are all scored as 1 and one for the decay function.
Hope that helps.

Cheers,
Britta

POST testidx/test/1
{
"num": 5
}

POST testidx/test/2
{
"num": 3
}

POST testidx/test/3
{
"num": 1
}
POST testidx/test/4
{
"num": 0
}

POST testidx/test/_search
{
"query": {
"function_score": {
"functions": [
{
"filter": {
"range": {
"num": {
"gte": 1,
"lte": 5
}
}
},
"linear": {
"num": {
"origin": 5,
"scale": 4,
"decay": 0.2
}
}
},
{
"filter": {
"range": {
"num": {
"lt": 1
}
}
},
"boost_factor": 0.2
}
],
"boost": 5
}
}
}

On Tue, Nov 26, 2013 at 2:31 PM, Vinay Gurram
g.vinayvenkatakrishna@gmail.com wrote:

Hi
I want to search for a hotel based on distance. I would like to give boost
based on the range . Like 5 for 0-10km, 3 for 10-100km, 1 for greater than
100km .
I proceded with Function Score Query

"function_score": {
"functions": [
{

        "boost_factor": "5",
        "filter": {geo Range Filter(0-10)}
    },

    {

        "boost_factor": "3",
        "filter": {geo Range Filter(10-100)}
    },{

        "boost_factor": "1",
        "filter": {geo Range Filter(100-1000)}
    },

],
"query": {...},
"score_mode": "first"

}

I have a few questions.

  1. Does this query calculate the distance thrice for same document because
    of 3 filters? .
  2. how I use decay function to implement the same functionality?

Thank you,
Vinay

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALhJbBiXD1AgT%2BFZzKUQVN6YOYCOgq5APhvdBePtkLLb3y3waw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.