# Native script support in TermsStatsFacet query

**URL:** <https://discuss.elastic.co/t/native-script-support-in-termsstatsfacet-query/14807>\
**Category:** Elasticsearch\
**Created:** [December 11, 2013, 6:55am UTC](https://discuss.elastic.co/t/native-script-support-in-termsstatsfacet-query/14807 "2013-12-11T06:55:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hanish\_Bansal](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@Hanish\_Bansal](https://discuss.elastic.co/u/Hanish_Bansal)\
**Post date:** [December 11, 2013, 6:55am UTC](https://discuss.elastic.co/t/native-script-support-in-termsstatsfacet-query/14807/1 "2013-12-11T06:55:21Z")

</div>

Hi All,

I have registered some custom java based scripts using native script  
support in elasticsearch.

Now i am able to use those script using below query:

{  
"query" : {  
"match\_all" : { }  
},  
"script\_fields": {  
"MessageReverted": {  
"script": "reverse",  
"lang": "native",  
"params": {  
"field": "field1"  
}  
}  
}  
}

Where _reverse_ is my script name that is defined in elasticsearch.yml as:

script.native._reverse_.type :  
org.elasticsearch.examples.nativescript.script.ReverseStringFactory

I am able to get expected results.

Now i want similar functionality in facet functions. I am using term stat  
facet query  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-stats-facet.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-stats-facet.html).

By default _TermsStatsFacet_ query supports below functions:

```
    Text getTerm();

    Number getTermAsNumber();

    long getCount();

    long getTotalCount();

    double getMin();

    double getMax();

    double getTotal();

    double getMean();

```

TermsStatsFacet query is really useful feature to compute stats on a field. I  
am already using it in some of my use cases. One of my use case is also to  
compute some custom stats on a field.

Is there any way to register some custom functions to these using native  
scripts or any other method ?

## Thanks in advance !!

_Thanks & Regards_  
_Hanish Bansal_

--  
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/CAB0WE8YFLnmcdsitk40Yx\_Z74%2BFcJZ5q7eUs6o-ndQQiSas2Kw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAB0WE8YFLnmcdsitk40Yx_Z74%2BFcJZ5q7eUs6o-ndQQiSas2Kw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:02am UTC](https://discuss.elastic.co/t/native-script-support-in-termsstatsfacet-query/14807/2 "2017-07-06T02:02:03Z")

</div>


