Composing function scores


(Ivan Brusic) #1

I have a couple of questions regarding function scores. I probably already
know the answers, but just wanted to double-check with the community. I am
still on version 1.1.1, so perhaps things have changed since then.

First question is regarding ordering and efficiency. Currently, my query is
a standard filtered query with a function score surrounding the inner most
query:

POST /_search
{
"query": {
"filtered": {
"query": {
"function_score": {
"query": {
...
},
"script_score": {
"script": "..."
},
"boost_mode": "multiply"
}
},
"filter": {
...
}
}
}
}

While attempting to fine-tune further my queries, I was wondering if it
made sense to move the function_score higher up the chain:

POST /_search
{
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
...
},
"filter": {
...
}
}
},
"script_score": {
"script": "..."
},
"boost_mode": "multiply"
}
}
}

Both work as intended. I would suspect that the efficiency is the same
since the function is still scoring the same pre-filtered documents. Not
sure how this change would affect caching, if at all.

Next question is regarding applying different function_scores. Beside using
the script_score, I know also want to use boost functions. Using version
1.1.1, I cannot apply both script_scores and functions:

POST /_search
{
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
...
},
"filter": {
...
}
}
},
"script_score": {
"script": "..."
},
"functions": [
{
"filter": {
...
},
"boost_factor": 1
}
]
"boost_mode": "multiply"
}
}
}

Chaining the function scores does work. The original script_score function
is now wrapped by the boost functions.

POST /_search
{
"query": {
"function_score": {
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
...
},
"filter": {
...
}
}
},
"script_score": {
"script": "..."
},
"boost_mode": "multiply"
}
},
"functions": [
{
"filter": {
...
},
"boost_factor": 1
}
]
}
}
}

Should I have been able to use both types of scripts at the same time? I
also do not think there will be any difference in the ordering, but did I
perhaps overlook something?

Cheers,

Ivan

--
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/CALY%3DcQBpX9Ux4AVaBcAVZc3b3cmusR7vKuG85%2BBKwr8yXqwK4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2