# Document boosting vs function score boosting

**URL:** <https://discuss.elastic.co/t/document-boosting-vs-function-score-boosting/20121>\
**Category:** Elasticsearch\
**Created:** [October 7, 2014, 4:01pm UTC](https://discuss.elastic.co/t/document-boosting-vs-function-score-boosting/20121 "2014-10-07T16:01:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton\_Pirker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anton_pirker/32/1223_2.png) [@Anton\_Pirker](https://discuss.elastic.co/u/Anton_Pirker)\
**Post date:** [October 7, 2014, 4:01pm UTC](https://discuss.elastic.co/t/document-boosting-vs-function-score-boosting/20121/1 "2014-10-07T16:01:29Z")

</div>

Hello all!

I am new to ElasticSearch and I am trying to move some of my documents to  
the top of the search results. (I have a "is\_premium" field in my documents  
and also a "popularity" value that is calculated by our system) The premium  
documents should always be on the top of the search results (huge boost  
factor) and popularity value should change the ordering of the rest of the  
search results (small boost factor)

So I think I need some document boosting. I already have added a "boost"  
value when adding documents to the index. This works as expected for  
putting all "is\_premium" documents to the top.  
But now I have read in a blog post [1] that this way of doing things is  
deprecated. A better way of boosting this is doing a function score query  
where you calculate the boost value on query time, not on index time like  
with document boosting.

So my question are:

a) Is document boosting on index time really deprecated and if yes, why?

b) I need some in wrapping my head around creating a custom query with  
function score boosting (I use Django Haystack with Elastic-Search so no  
manual query creation was necessary up until now.)  
This is the test query I put together:

{  
"query": {  
"function\_score": {  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"default\_field": "\_all",  
"query": "tour de france"  
}  
}  
]  
}  
},  
"script\_score": {  
"script": "\_score \* 1000 \* doc['popularity'].value"  
}  
}  
}  
}

But I get an error which I do not understand:  
QueryParsingException[[haystack] script\_score the script could not be  
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled]

Has anyone some tips for me on how to get this query working?

Thanks in advance!  
Anton

1: [http://blog.brusic.com/2014/02/document-boosting-in-elasticsearch.html](http://blog.brusic.com/2014/02/document-boosting-in-elasticsearch.html)

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ffc701fd-c859-4506-a0df-7e8f31a8b6bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ffc701fd-c859-4506-a0df-7e8f31a8b6bf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [October 7, 2014, 4:51pm UTC](https://discuss.elastic.co/t/document-boosting-vs-function-score-boosting/20121/2 "2014-10-07T16:51:45Z")

</div>

Look into field value factor, which was added in 1.2

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan  
On Oct 7, 2014 9:01 AM, "Anton Pirker" [anton@ignaz.at](mailto:anton@ignaz.at) wrote:

> Hello all!
> 
> I am new to Elasticsearch and I am trying to move some of my documents to  
> the top of the search results. (I have a "is\_premium" field in my documents  
> and also a "popularity" value that is calculated by our system) The premium  
> documents should always be on the top of the search results (huge boost  
> factor) and popularity value should change the ordering of the rest of the  
> search results (small boost factor)
> 
> So I think I need some document boosting. I already have added a "boost"  
> value when adding documents to the index. This works as expected for  
> putting all "is\_premium" documents to the top.  
> But now I have read in a blog post [1] that this way of doing things is  
> deprecated. A better way of boosting this is doing a function score query  
> where you calculate the boost value on query time, not on index time like  
> with document boosting.
> 
> So my question are:
> 
> a) Is document boosting on index time really deprecated and if yes, why?
> 
> b) I need some in wrapping my head around creating a custom query with  
> function score boosting (I use Django Haystack with Elastic-Search so no  
> manual query creation was necessary up until now.)  
> This is the test query I put together:
> 
> {  
> "query": {  
> "function\_score": {  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "query\_string": {  
> "default\_field": "\_all",  
> "query": "tour de france"  
> }  
> }  
> ]  
> }  
> },  
> "script\_score": {  
> "script": "\_score \* 1000 \* doc['popularity'].value"  
> }  
> }  
> }  
> }
> 
> But I get an error which I do not understand:  
> QueryParsingException[[haystack] script\_score the script could not be  
> loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled]
> 
> Has anyone some tips for me on how to get this query working?
> 
> Thanks in advance!  
> Anton
> 
> 1: [{ "blog" : "brusic" }: Document boosting in Elasticsearch](http://blog.brusic.com/2014/02/document-boosting-in-elasticsearch.html)
> 
> --  
> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/ffc701fd-c859-4506-a0df-7e8f31a8b6bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ffc701fd-c859-4506-a0df-7e8f31a8b6bf%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/ffc701fd-c859-4506-a0df-7e8f31a8b6bf%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ffc701fd-c859-4506-a0df-7e8f31a8b6bf%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCGv1YH82VxcxArfRet4uH2qZtHrHOaRv0xSzJAX9Woxg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCGv1YH82VxcxArfRet4uH2qZtHrHOaRv0xSzJAX9Woxg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:57am UTC](https://discuss.elastic.co/t/document-boosting-vs-function-score-boosting/20121/3 "2017-07-06T00:57:49Z")

</div>


