# Unexpected behavior (to me :-) from function\_score

**URL:** https://discuss.elastic.co/t/unexpected-behavior-to-me-from-function-score/22874
**Category:** Elasticsearch
**Created:** [March 24, 2015, 9:15pm UTC](https://discuss.elastic.co/t/unexpected-behavior-to-me-from-function-score/22874 "2015-03-24T21:15:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jan58\_wandelaar](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jan58\_wandelaar](https://discuss.elastic.co/u/jan58_wandelaar)
#### Post date: [March 24, 2015, 9:15pm UTC](https://discuss.elastic.co/t/unexpected-behavior-to-me-from-function-score/22874/1 "2015-03-24T21:15:41Z")

</div>

Hi All,

Starting to play with function\_score and doc\_values...  
I have a set of 30 documents with integers, ranging from 1 to 30.

Now I want a query that returns all documents with value 5 on top, followed  
by the rest of the documents, scored by their distance to 5.

Query:  
"query": {  
"function\_score": {  
"query": {"match\_all": {}},  
"boost\_mode": "replace",  
"functions": [  
{  
"gauss": {  
"int\_field": {  
"origin": 5,  
"scale": 5,  
"offset": 2,  
"decay" : 0.1  
}}  
}  
]  
}  
}

This returns the document with 5 with a score of 1 (expected), followed by  
the rest of the documents with a score 0 (NOT expected).

Does someone see what I'm doing wrong?

Looking at the explain, I see weird values for the doc\_values.  
Following is the explain for the top document (with 5 as its value). Note  
the stated values for doc\_value and origin!  
"\_explanation": {  
"value": 1,  
"description": "function score, product of:",  
"details": [  
{  
"value": 1,  
"description": "Math.min of",  
"details": [  
{  
"value": 1,  
"description": "function score, score mode  
[multiply]",  
"details": [  
{  
"value": 1,  
"description": "function score, product  
of:",  
"details": [  
{  
"value": 1,  
"description": "match filter: _:_"  
},  
{  
"value": 1,  
"description": "Function for field  
int\_field:",  
"details": [  
{  
"value": 1,  
"description":  
"exp(-0.5\*pow(MIN of: [Math.max(Math.abs(-6.20093664E13(=doc value) -  
-6.20093664E13(=origin))) - 2.0(=offset), 0)],2.0)/5.428681023790649)"  
}  
]  
}  
]  
}  
]  
},  
{  
"value": 3.4028235e+38,  
"description": "maxBoost"  
}  
]  
},

Best regards,  
Jan

--  
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/e2d438dd-26af-43df-b50d-21fca69121f6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e2d438dd-26af-43df-b50d-21fca69121f6%40googlegroups.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:24am UTC](https://discuss.elastic.co/t/unexpected-behavior-to-me-from-function-score/22874/2 "2017-07-06T00:24:17Z")

</div>


