# Just pushed: custom\_score query

**URL:** <https://discuss.elastic.co/t/just-pushed-custom-score-query/3016>\
**Category:** Elasticsearch\
**Created:** [June 14, 2010, 12:19am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016 "2010-06-14T00:19:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 14, 2010, 12:19am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/1 "2010-06-14T00:19:35Z")

</div>

Hi,

custom\_score query support just pushed to master. This allows to easily  
control the scoring (or completely replace) of a query based on the query  
score and other document field values. Much more is explained in the issue:  
[http://github.com/elasticsearch/elasticsearch/issues/220](http://github.com/elasticsearch/elasticsearch/issues/220), but here is a  
simple sample:

"custom\_score" : {  
"query" : {  
....  
},  
"script" : "score \* doc['my\_numeric\_field'].value"  
}

This was requested by several users, for example, to control the scoring  
based on recency of documents.

-shay.banon

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [June 15, 2010, 5:17am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/2 "2010-06-15T05:17:27Z")

</div>

Hi,

So one can put any sort of a custom formula in that "script" value,  
ha?

Sounds like the equivalent of Solr's function queries? (  
[http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery) )  
Or maybe a basic version of function queries?

## Thanks, Otis

Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch  
Lucene ecosystem search :: [http://search-lucene.com/](http://search-lucene.com/)

On Jun 13, 8:19 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Hi,
> 
> custom\_score query support just pushed to master. This allows to easily  
> control the scoring (or completely replace) of a query based on the query  
> score and other document field values. Much more is explained in the issue:[Query DSL: custom score (scripted) query · Issue #220 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/220), but here is a  
> simple sample:
> 
> "custom\_score" : {  
> "query" : {  
> ....  
> },  
> "script" : "score \* doc['my\_numeric\_field'].value"
> 
> }
> 
> This was requested by several users, for example, to control the scoring  
> based on recency of documents.
> 
> -shay.banon

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 15, 2010, 7:30am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/3 "2010-06-15T07:30:00Z")

</div>

Yes, it similar in spirit to function queries, it is actually modeled after  
Lucene custom score query (but not used directly). Why do you say its a  
basic version of function queries, is there something you can do with the  
other that you can't do with this?

-shay.banon

On Tue, Jun 15, 2010 at 8:17 AM, Otis [otis.gospodnetic@gmail.com](mailto:otis.gospodnetic@gmail.com) wrote:

> Hi,
> 
> So one can put any sort of a custom formula in that "script" value,  
> ha?
> 
> Sounds like the equivalent of Solr's function queries? (  
> [http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery) )  
> Or maybe a basic version of function queries?
> 
> ## Thanks, Otis
> 
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch  
> Lucene ecosystem search :: [http://search-lucene.com/](http://search-lucene.com/)
> 
> On Jun 13, 8:19 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Hi,
> > 
> > custom\_score query support just pushed to master. This allows to  
> > easily  
> > control the scoring (or completely replace) of a query based on the query  
> > score and other document field values. Much more is explained in the  
> > issue:[Query DSL: custom score (scripted) query · Issue #220 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/220), but here  
> > is a  
> > simple sample:
> > 
> > "custom\_score" : {  
> > "query" : {  
> > ....  
> > },  
> > "script" : "score \* doc['my\_numeric\_field'].value"
> > 
> > }
> > 
> > This was requested by several users, for example, to control the  
> > scoring  
> > based on recency of documents.
> > 
> > -shay.banon

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [June 16, 2010, 4:27am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/4 "2010-06-16T04:27:55Z")

</div>

Hi,

Yeah, I purposely said "basic" simply because I wasn't sure whether  
the new "script" stuff can be used to do all those things listed on  
[http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery) . Can it? It would be  
great to list a few examples somewhere, so we can get a better idea.

For example, can the "script" functionality be used for these  
(randomly picked from the above Wiki page):

[http://wiki.apache.org/solr/FunctionQuery#ord](http://wiki.apache.org/solr/FunctionQuery#ord)  
[http://wiki.apache.org/solr/FunctionQuery#sum](http://wiki.apache.org/solr/FunctionQuery#sum)  
[http://wiki.apache.org/solr/FunctionQuery#recip](http://wiki.apache.org/solr/FunctionQuery#recip)  
[http://wiki.apache.org/solr/FunctionQuery#ms](http://wiki.apache.org/solr/FunctionQuery#ms)  
[http://wiki.apache.org/solr/FunctionQuery#geohash\_-\_Convert\_to\_geohash](http://wiki.apache.org/solr/FunctionQuery#geohash_-_Convert_to_geohash)  
[http://wiki.apache.org/solr/FunctionQuery#strdist](http://wiki.apache.org/solr/FunctionQuery#strdist)

## Thanks, Otis

Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch  
Lucene ecosystem search :: [http://search-lucene.com/](http://search-lucene.com/)

On Jun 15, 3:30 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Yes, it similar in spirit to function queries, it is actually modeled after  
> Lucene custom score query (but not used directly). Why do you say its a  
> basic version of function queries, is there something you can do with the  
> other that you can't do with this?
> 
> -shay.banon
> 
> On Tue, Jun 15, 2010 at 8:17 AM, Otis [otis.gospodne...@gmail.com](mailto:otis.gospodne...@gmail.com) wrote:
> 
> > Hi,
> 
> > So one can put any sort of a custom formula in that "script" value,  
> > ha?
> 
> > Sounds like the equivalent of Solr's function queries? (  
> > [http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery))  
> > Or maybe a basic version of function queries?
> 
> > ## Thanks, Otis
> > 
> > Sematext ::[http://sematext.com/::](http://sematext.com/::) Solr - Lucene - Nutch  
> > Lucene ecosystem search ::[http://search-lucene.com/](http://search-lucene.com/)
> 
> > On Jun 13, 8:19 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Hi,
> 
> > > custom\_score query support just pushed to master. This allows to  
> > > easily  
> > > control the scoring (or completely replace) of a query based on the query  
> > > score and other document field values. Much more is explained in the  
> > > issue:[Query DSL: custom score (scripted) query · Issue #220 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/220), but here  
> > > is a  
> > > simple sample:
> 
> > > "custom\_score" : {  
> > > "query" : {  
> > > ....  
> > > },  
> > > "script" : "score \* doc['my\_numeric\_field'].value"
> 
> > > }
> 
> > > This was requested by several users, for example, to control the  
> > > scoring  
> > > based on recency of documents.
> 
> > > -shay.banon

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 16, 2010, 8:26am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/5 "2010-06-16T08:26:19Z")

</div>

This is just mvel script running, you can do what you want with it, its  
basically code... . So, you can do all of the above and much much more since  
you are not bounded by static functions.

-shay.banon

On Wed, Jun 16, 2010 at 7:27 AM, Otis [otis.gospodnetic@gmail.com](mailto:otis.gospodnetic@gmail.com) wrote:

> Hi,
> 
> Yeah, I purposely said "basic" simply because I wasn't sure whether  
> the new "script" stuff can be used to do all those things listed on  
> [http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery) . Can it? It would be  
> great to list a few examples somewhere, so we can get a better idea.
> 
> For example, can the "script" functionality be used for these  
> (randomly picked from the above Wiki page):
> 
> [http://wiki.apache.org/solr/FunctionQuery#ord](http://wiki.apache.org/solr/FunctionQuery#ord)  
> [http://wiki.apache.org/solr/FunctionQuery#sum](http://wiki.apache.org/solr/FunctionQuery#sum)  
> [http://wiki.apache.org/solr/FunctionQuery#recip](http://wiki.apache.org/solr/FunctionQuery#recip)  
> [http://wiki.apache.org/solr/FunctionQuery#ms](http://wiki.apache.org/solr/FunctionQuery#ms)  
> [http://wiki.apache.org/solr/FunctionQuery#geohash\_-\_Convert\_to\_geohash](http://wiki.apache.org/solr/FunctionQuery#geohash_-_Convert_to_geohash)  
> [http://wiki.apache.org/solr/FunctionQuery#strdist](http://wiki.apache.org/solr/FunctionQuery#strdist)
> 
> ## Thanks, Otis
> 
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch  
> Lucene ecosystem search :: [http://search-lucene.com/](http://search-lucene.com/)
> 
> On Jun 15, 3:30 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Yes, it similar in spirit to function queries, it is actually modeled  
> > after  
> > Lucene custom score query (but not used directly). Why do you say its a  
> > basic version of function queries, is there something you can do with the  
> > other that you can't do with this?
> > 
> > -shay.banon
> > 
> > On Tue, Jun 15, 2010 at 8:17 AM, Otis [otis.gospodne...@gmail.com](mailto:otis.gospodne...@gmail.com)  
> > wrote:
> > 
> > > Hi,
> > 
> > > So one can put any sort of a custom formula in that "script" value,  
> > > ha?
> > 
> > > Sounds like the equivalent of Solr's function queries? (  
> > > [http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery))  
> > > Or maybe a basic version of function queries?
> > 
> > > ## Thanks, Otis
> > > 
> > > Sematext ::[http://sematext.com/::](http://sematext.com/::) Solr - Lucene - Nutch  
> > > Lucene ecosystem search ::[http://search-lucene.com/](http://search-lucene.com/)
> > 
> > > On Jun 13, 8:19 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > 
> > > > Hi,
> > 
> > > > custom\_score query support just pushed to master. This allows to  
> > > > easily  
> > > > control the scoring (or completely replace) of a query based on the  
> > > > query  
> > > > score and other document field values. Much more is explained in the  
> > > > issue:[Query DSL: custom score (scripted) query · Issue #220 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/220), but  
> > > > here  
> > > > is a  
> > > > simple sample:
> > 
> > > > "custom\_score" : {  
> > > > "query" : {  
> > > > ....  
> > > > },  
> > > > "script" : "score \* doc['my\_numeric\_field'].value"
> > 
> > > > }
> > 
> > > > This was requested by several users, for example, to control the  
> > > > scoring  
> > > > based on recency of documents.
> > 
> > > > -shay.banon

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [June 16, 2010, 9:01pm UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/6 "2010-06-16T21:01:33Z")

</div>

Oooooh, I see. Never heard of mvel, but it's a mvelous discovery.  
Very nice and handy.

## Otis

Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch  
Lucene ecosystem search :: [http://search-lucene.com/](http://search-lucene.com/)

On Jun 16, 4:26 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> This is just mvel script running, you can do what you want with it, its  
> basically code... . So, you can do all of the above and much much more since  
> you are not bounded by static functions.
> 
> -shay.banon
> 
> On Wed, Jun 16, 2010 at 7:27 AM, Otis [otis.gospodne...@gmail.com](mailto:otis.gospodne...@gmail.com) wrote:
> 
> > Hi,
> 
> > Yeah, I purposely said "basic" simply because I wasn't sure whether  
> > the new "script" stuff can be used to do all those things listed on  
> > [http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery). Can it? It would be  
> > great to list a few examples somewhere, so we can get a better idea.
> 
> > For example, can the "script" functionality be used for these  
> > (randomly picked from the above Wiki page):
> 
> > [http://wiki.apache.org/solr/FunctionQuery#ord](http://wiki.apache.org/solr/FunctionQuery#ord)  
> > [http://wiki.apache.org/solr/FunctionQuery#sum](http://wiki.apache.org/solr/FunctionQuery#sum)  
> > [http://wiki.apache.org/solr/FunctionQuery#recip](http://wiki.apache.org/solr/FunctionQuery#recip)  
> > [http://wiki.apache.org/solr/FunctionQuery#ms](http://wiki.apache.org/solr/FunctionQuery#ms)  
> > [http://wiki.apache.org/solr/FunctionQuery#geohash\_-\_Convert\_to\_geohash](http://wiki.apache.org/solr/FunctionQuery#geohash_-_Convert_to_geohash)  
> > [http://wiki.apache.org/solr/FunctionQuery#strdist](http://wiki.apache.org/solr/FunctionQuery#strdist)
> 
> > ## Thanks, Otis
> > 
> > Sematext ::[http://sematext.com/::](http://sematext.com/::) Solr - Lucene - Nutch  
> > Lucene ecosystem search ::[http://search-lucene.com/](http://search-lucene.com/)
> 
> > On Jun 15, 3:30 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Yes, it similar in spirit to function queries, it is actually modeled  
> > > after  
> > > Lucene custom score query (but not used directly). Why do you say its a  
> > > basic version of function queries, is there something you can do with the  
> > > other that you can't do with this?
> 
> > > -shay.banon
> 
> > > On Tue, Jun 15, 2010 at 8:17 AM, Otis [otis.gospodne...@gmail.com](mailto:otis.gospodne...@gmail.com)  
> > > wrote:
> > > 
> > > > Hi,
> 
> > > > So one can put any sort of a custom formula in that "script" value,  
> > > > ha?
> 
> > > > Sounds like the equivalent of Solr's function queries? (  
> > > > [http://wiki.apache.org/solr/FunctionQuery](http://wiki.apache.org/solr/FunctionQuery))  
> > > > Or maybe a basic version of function queries?
> 
> > > > ## Thanks, Otis
> > > > 
> > > > Sematext ::[Solr Consulting](http://sematext.com/::Solr) - Lucene - Nutch  
> > > > Lucene ecosystem search ::[http://search-lucene.com/](http://search-lucene.com/)
> 
> > > > On Jun 13, 8:19 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > > 
> > > > > Hi,
> 
> > > > > custom\_score query support just pushed to master. This allows to  
> > > > > easily  
> > > > > control the scoring (or completely replace) of a query based on the  
> > > > > query  
> > > > > score and other document field values. Much more is explained in the  
> > > > > issue:[Query DSL: custom score (scripted) query · Issue #220 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/220), but  
> > > > > here  
> > > > > is a  
> > > > > simple sample:
> 
> > > > > "custom\_score" : {  
> > > > > "query" : {  
> > > > > ....  
> > > > > },  
> > > > > "script" : "score \* doc['my\_numeric\_field'].value"
> 
> > > > > }
> 
> > > > > This was requested by several users, for example, to control the  
> > > > > scoring  
> > > > > based on recency of documents.
> 
> > > > > -shay.banon

---

<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, 4:23am UTC](https://discuss.elastic.co/t/just-pushed-custom-score-query/3016/7 "2017-07-06T04:23:14Z")

</div>


