# Function Score Query and Native scripts

**URL:** <https://discuss.elastic.co/t/function-score-query-and-native-scripts/16977>\
**Category:** Elasticsearch\
**Created:** [April 12, 2014, 5:49pm UTC](https://discuss.elastic.co/t/function-score-query-and-native-scripts/16977 "2014-04-12T17:49:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_T](https://avatars.discourse-cdn.com/v4/letter/e/a587f6/32.png) [@Eric\_T](https://discuss.elastic.co/u/Eric_T)\
**Post date:** [April 12, 2014, 5:49pm UTC](https://discuss.elastic.co/t/function-score-query-and-native-scripts/16977/1 "2014-04-12T17:49:32Z")

</div>

Hi,

The function score documentation doesn't mention any support for native  
scripts, does it still work for the Function Score Query, if so is it the  
same syntax?  
I'm using the custom\_filters\_score query with a native script but the query  
is deprecated in the latest ES version. I'm still using 0.90.3 but I plan  
to upgrade to the latest version.

It says that the script\_score function for function\_score is cached. Does  
this provide the same performance as the Native script? I'm wondering if  
it's necessary to still use a native script or convert it to the  
script\_score function

thanks  
Eric

--  
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/3ac58df6-742f-4bcb-8ac2-856adeeeeb15%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3ac58df6-742f-4bcb-8ac2-856adeeeeb15%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![David\_Smith\_2](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@David\_Smith\_2](https://discuss.elastic.co/u/David_Smith_2)\
**Post date:** [April 18, 2014, 7:49pm UTC](https://discuss.elastic.co/t/function-score-query-and-native-scripts/16977/2 "2014-04-18T19:49:07Z")

</div>

Yes, function score query works with native scripts. We use it with them.

I'm not sure whether native scripts are automatically cached.

On Saturday, April 12, 2014 1:49:32 PM UTC-4, Eric T wrote:

> Hi,
> 
> The function score documentation doesn't mention any support for native  
> scripts, does it still work for the Function Score Query, if so is it the  
> same syntax?  
> I'm using the custom\_filters\_score query with a native script but the  
> query is deprecated in the latest ES version. I'm still using 0.90.3 but I  
> plan to upgrade to the latest version.
> 
> It says that the script\_score function for function\_score is cached. Does  
> this provide the same performance as the Native script? I'm wondering if  
> it's necessary to still use a native script or convert it to the  
> script\_score function
> 
> thanks  
> Eric

--  
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/edddb638-0b4e-49b8-8925-257064dc0afe%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edddb638-0b4e-49b8-8925-257064dc0afe%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![David\_Smith\_2](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@David\_Smith\_2](https://discuss.elastic.co/u/David_Smith_2)\
**Post date:** [April 18, 2014, 7:55pm UTC](https://discuss.elastic.co/t/function-score-query-and-native-scripts/16977/3 "2014-04-18T19:55:49Z")

</div>

You can use a function score query with a native script in this manner.

{

"function\_score" : {

```
"query" : {

  "match_all" : { }

},

"functions" : [ {

  "filter" : {

    "terms" : {

      "myfield" : ["103", "104", "134", "180"],

      "_cache" : true

    }

  },

  "script_score" : {

    "script" : "myscriptname",

    "lang" : "native",

    "params" : {

      "myparam1" : "something",

      "myparam2" : "somethingElse"

    }

  }

} ],

"score_mode" : "sum"

```

}

}

--  
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/cb47555a-dd96-4dde-bf20-e80f42f975cd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cb47555a-dd96-4dde-bf20-e80f42f975cd%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:34am UTC](https://discuss.elastic.co/t/function-score-query-and-native-scripts/16977/4 "2017-07-06T01:34:58Z")

</div>


