# Unable to get function\_score to work

**URL:** <https://discuss.elastic.co/t/unable-to-get-function-score-to-work/16808>\
**Category:** Elasticsearch\
**Created:** [April 3, 2014, 8:03pm UTC](https://discuss.elastic.co/t/unable-to-get-function-score-to-work/16808 "2014-04-03T20:03:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivasan\_Ramaswamy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivasan_ramaswamy/32/74106_2.png) [@Srinivasan\_Ramaswamy](https://discuss.elastic.co/u/Srinivasan_Ramaswamy)\
**Post date:** [April 3, 2014, 8:03pm UTC](https://discuss.elastic.co/t/unable-to-get-function-score-to-work/16808/1 "2014-04-03T20:03:04Z")

</div>

Hi

I just started playing around with elastic search and I am trying out the  
examples in the website with my data. I am trying to get custom scoring  
working. I am following the example from  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/query-dsl-function-score-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/query-dsl-function-score-query.html)  
But unable to get the example working

{  
"query" : {  
"function\_score": {  
"boost\_mode": "replace",  
"query": {"design.PRODUCT\_DESC":"cool"},  
"script\_score": {  
"params": {  
"param1": 2,  
"param2": 3.1  
},  
"script": "\_score \* doc['design.CLICKS'].value / pow(param1,  
param2)"  
}  
}  
}  
}

I tried this query and i get the error

Caused by: org.elasticsearch.index.query.QueryParsingException: [designs]  
[\_na] query malformed, no field after start\_object

at  
org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:216)

at  
org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser.parse(FunctionScoreQueryParser.java:89)

at  
org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:223)

at  
org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:330)

at  
org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:260)

at  
org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)

at  
org.elasticsearch.search.SearchService.parseSource(SearchService.java:622)

Any help would be appreciated.

Thanks  
Srini

--  
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/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![luizgpsantos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luizgpsantos/32/608_2.png) [@luizgpsantos](https://discuss.elastic.co/u/luizgpsantos)\
**Post date:** [April 3, 2014, 8:55pm UTC](https://discuss.elastic.co/t/unable-to-get-function-score-to-work/16808/2 "2014-04-03T20:55:57Z")

</div>

Hi Srinivasan,

It seems your intern "query" is malformed. Try this:

{  
"query": {  
"function\_score": {  
"boost\_mode": "replace",  
"query": {  
"match\_all": {}  
},  
"script\_score": {  
"params": {  
"param1": 2,  
"param2": 3.1  
},  
"script": "\_score \* doc['design.CLICKS'].value / pow(param1,  
param2)"  
}  
}  
}  
}

Cheers,  
Luiz Guilherme

On Thu, Apr 3, 2014 at 5:03 PM, Srinivasan Ramaswamy [ursvasan@gmail.com](mailto:ursvasan@gmail.com)wrote:

> Hi
> 
> I just started playing around with Elasticsearch and I am trying out the  
> examples in the website with my data. I am trying to get custom scoring  
> working. I am following the example from  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/query-dsl-function-score-query.html)
> 
> But unable to get the example working
> 
> {  
> "query" : {  
> "function\_score": {  
> "boost\_mode": "replace",  
> "query": {"design.PRODUCT\_DESC":"cool"},  
> "script\_score": {  
> "params": {  
> "param1": 2,  
> "param2": 3.1  
> },  
> "script": "\_score \* doc['design.CLICKS'].value / pow(param1,  
> param2)"  
> }  
> }  
> }  
> }
> 
> I tried this query and i get the error
> 
> Caused by: org.elasticsearch.index.query.QueryParsingException: [designs]  
> [\_na] query malformed, no field after start\_object
> 
> at  
> org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:216)
> 
> at  
> org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser.parse(FunctionScoreQueryParser.java:89)
> 
> at  
> org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:223)
> 
> at  
> org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:330)
> 
> at  
> org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:260)
> 
> at  
> org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
> 
> at  
> org.elasticsearch.search.SearchService.parseSource(SearchService.java:622)
> 
> Any help would be appreciated.
> 
> Thanks  
> Srini
> 
> --  
> 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/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Luiz Guilherme P. Santos

--  
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/CAMdL%3DZGr12cwOJ\_3DXUfPFefn\_jmWhbj95wXw%3D2UZVQiZkTE1Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAMdL%3DZGr12cwOJ_3DXUfPFefn_jmWhbj95wXw%3D2UZVQiZkTE1Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Srinivasan\_Ramaswamy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivasan_ramaswamy/32/74106_2.png) [@Srinivasan\_Ramaswamy](https://discuss.elastic.co/u/Srinivasan_Ramaswamy)\
**Post date:** [April 3, 2014, 9:29pm UTC](https://discuss.elastic.co/t/unable-to-get-function-score-to-work/16808/3 "2014-04-03T21:29:50Z")

</div>

Thanks Luiz, that was really helpful 🙂 The examples in the guide could be  
made more helpful. After you pointed out the the location of the error I  
got it working with

{  
"query": {  
"function\_score": {  
"boost\_mode": "replace",  
"query": {  
"match": { "design.PRODUCT\_DESC":"cool"}  
},  
"script\_score": {  
"params": {  
"param1": 2,  
"param2": 3.1  
},  
"script": "\_score \* doc['design.CLICKS'].value / pow(param1,  
param2)"  
}  
}  
}  
}

Thanks  
Srini

On Thursday, April 3, 2014 1:55:57 PM UTC-7, Luiz Guilherme wrote:

> Hi Srinivasan,
> 
> It seems your intern "query" is malformed. Try this:
> 
> {  
> "query": {  
> "function\_score": {  
> "boost\_mode": "replace",  
> "query": {  
> "match\_all": {}  
> },  
> "script\_score": {  
> "params": {  
> "param1": 2,  
> "param2": 3.1  
> },  
> "script": "\_score \* doc['design.CLICKS'].value / pow(param1,  
> param2)"  
> }  
> }  
> }  
> }
> 
> Cheers,  
> Luiz Guilherme
> 
> On Thu, Apr 3, 2014 at 5:03 PM, Srinivasan Ramaswamy \<[ursv...@gmail.com](mailto:ursv...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi
> > 
> > I just started playing around with Elasticsearch and I am trying out the  
> > examples in the website with my data. I am trying to get custom scoring  
> > working. I am following the example from  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/query-dsl-function-score-query.html)
> > 
> > But unable to get the example working
> > 
> > {  
> > "query" : {  
> > "function\_score": {  
> > "boost\_mode": "replace",  
> > "query": {"design.PRODUCT\_DESC":"cool"},  
> > "script\_score": {  
> > "params": {  
> > "param1": 2,  
> > "param2": 3.1  
> > },  
> > "script": "\_score \* doc['design.CLICKS'].value / pow(param1,  
> > param2)"  
> > }  
> > }  
> > }  
> > }
> > 
> > I tried this query and i get the error
> > 
> > Caused by: org.elasticsearch.index.query.QueryParsingException: [designs]  
> > [\_na] query malformed, no field after start\_object
> > 
> > at  
> > org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:216)
> > 
> > at  
> > org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser.parse(FunctionScoreQueryParser.java:89)
> > 
> > at  
> > org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:223)
> > 
> > at  
> > org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:330)
> > 
> > at  
> > org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:260)
> > 
> > at  
> > org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
> > 
> > at  
> > org.elasticsearch.search.SearchService.parseSource(SearchService.java:622)
> > 
> > Any help would be appreciated.
> > 
> > Thanks  
> > Srini
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16a38015-eaed-45af-9ad3-c474521b81a8%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Luiz Guilherme P. Santos

--  
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/6ae06fe2-2dfd-4a5c-920d-c2496c58c01b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ae06fe2-2dfd-4a5c-920d-c2496c58c01b%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, 1:38am UTC](https://discuss.elastic.co/t/unable-to-get-function-score-to-work/16808/4 "2017-07-06T01:38:22Z")

</div>


