# Using a statistical facet on a script\_field

**URL:** <https://discuss.elastic.co/t/using-a-statistical-facet-on-a-script-field/14293>\
**Category:** Elasticsearch\
**Created:** [November 6, 2013, 8:33pm UTC](https://discuss.elastic.co/t/using-a-statistical-facet-on-a-script-field/14293 "2013-11-06T20:33:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rastro](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@rastro](https://discuss.elastic.co/u/rastro)\
**Post date:** [November 6, 2013, 8:33pm UTC](https://discuss.elastic.co/t/using-a-statistical-facet-on-a-script-field/14293/1 "2013-11-06T20:33:06Z")

</div>

I can now create a script field:

```
    "script_fields" : {
                    "elapsed_tmp": {
                            "script": "singletimer",
                            "type": "float",
                            "lang": "js"
                    }
    }

```

This sets elapsed\_tmp to a value like 1.234.

I really need the min/max/mean of these values across the query, so I'd  
like to use the statistical facet:

```
   "facets" : {
            "stats0": {
                    "statistical": {
                            "field": "elapsed_tmp"
                    }
            }
    }

```

It complained that there was no mapping for elapsed\_tmp, so I added one.  
Now, it generates no errors, but returns no results:

"facets" : {  
"stats0" : {  
"\_type" : "statistical",  
"count" : 0,  
"total" : 0.0,  
"min" : "Infinity",  
"max" : "-Infinity",  
"mean" : 0.0,  
"sum\_of\_squares" : 0.0,  
"variance" : "NaN",  
"std\_deviation" : "NaN"  
}  
}

Anybody know how to make this work? Generically, the problem I'm trying to  
solve is to pull a piece of data out of message with a regex, and then run  
stats on that.

Thanks!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 14, 2013, 10:10am UTC](https://discuss.elastic.co/t/using-a-statistical-facet-on-a-script-field/14293/2 "2013-11-14T10:10:46Z")

</div>

Hey,

the statistical facet itself includes support for scripts fields, you  
should go with that. See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Wed, Nov 6, 2013 at 9:33 PM, rastro [robert@webmstr.com](mailto:robert@webmstr.com) wrote:

> I can now create a script field:
> 
> ```
> "script_fields" : {
> "elapsed_tmp": {
> "script": "singletimer",
> "type": "float",
> "lang": "js"
> }
> }
> 
> ```
> 
> This sets elapsed\_tmp to a value like 1.234.
> 
> I really need the min/max/mean of these values across the query, so I'd  
> like to use the statistical facet:
> 
> ```
> "facets" : {
> "stats0": {
> "statistical": {
> "field": "elapsed_tmp"
> }
> }
> }
> 
> ```
> 
> It complained that there was no mapping for elapsed\_tmp, so I added one.  
> Now, it generates no errors, but returns no results:
> 
> "facets" : {  
> "stats0" : {  
> "\_type" : "statistical",  
> "count" : 0,  
> "total" : 0.0,  
> "min" : "Infinity",  
> "max" : "-Infinity",  
> "mean" : 0.0,  
> "sum\_of\_squares" : 0.0,  
> "variance" : "NaN",  
> "std\_deviation" : "NaN"  
> }  
> }
> 
> Anybody know how to make this work? Generically, the problem I'm trying  
> to solve is to pull a piece of data out of message with a regex, and then  
> run stats on that.
> 
> Thanks!
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
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:07am UTC](https://discuss.elastic.co/t/using-a-statistical-facet-on-a-script-field/14293/3 "2017-07-06T02:07:09Z")

</div>


