# Script fields in query not showing up in Kibana visualize aggregation

**URL:** https://discuss.elastic.co/t/script-fields-in-query-not-showing-up-in-kibana-visualize-aggregation/61971
**Category:** Kibana
**Created:** [September 30, 2016, 11:00pm UTC](https://discuss.elastic.co/t/script-fields-in-query-not-showing-up-in-kibana-visualize-aggregation/61971 "2016-09-30T23:00:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![satheeshravir](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@satheeshravir](https://discuss.elastic.co/u/satheeshravir)
#### Post date: [September 30, 2016, 11:00pm UTC](https://discuss.elastic.co/t/script-fields-in-query-not-showing-up-in-kibana-visualize-aggregation/61971/1 "2016-09-30T23:00:08Z")

</div>

I am using the following search query in Kibana. Its returning the expected results. I am trying to aggregate vertical bar chart visualization using the script field. But the script fields "duration" and "state" isn't showing up in the drop down. Any idea why?

> {  
> "index": "logs\_test",  
> "query": {  
> "regexp": {  
> "body.message": ".\* ended ._"  
> }  
> },  
> "script\_fields": {  
> "duration": {  
> "type": "double",  
> "script": {  
> "lang": "groovy",  
> "file": "extract\_time"  
> }  
> },  
> "state": {  
> "type": "string",  
> "script": {  
> "lang": "groovy",  
> "file": "extract\_state"  
> }  
> }  
> },  
> "filter": [],  
> "highlight": {  
> "pre\_tags": [  
> "@kibana-highlighted-field@"  
> ],  
> "post\_tags": [  
> "@/kibana-highlighted-field@"  
> ],  
> "fields": {  
> "_": {}  
> },  
> "require\_field\_match": false,  
> "fragment\_size": 2147483647  
> }  
> }

---

<div class="post-metadata">

### Author: ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)
#### Post date: [October 5, 2016, 9:47pm UTC](https://discuss.elastic.co/t/script-fields-in-query-not-showing-up-in-kibana-visualize-aggregation/61971/2 "2016-10-05T21:47:06Z")

</div>

If I understand correctly, you've put the above query in the Kibana filter bar? Script fields from the filter bar won't show up as an option in the Viz editor. Only fields added via Kibana's [scripted field](https://www.elastic.co/guide/en/kibana/5.0/managing-fields.html#create-scripted-field) UI will show up. In 4.x you can only use lucene expressions for scripted fields, but in 5.x you'll be able to use the [Painless](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-painless.html) scripting language which should allow you to do what you want.

---

<div class="post-metadata">

### Author: ![satheeshravir](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@satheeshravir](https://discuss.elastic.co/u/satheeshravir)
#### Post date: [October 5, 2016, 10:03pm UTC](https://discuss.elastic.co/t/script-fields-in-query-not-showing-up-in-kibana-visualize-aggregation/61971/3 "2016-10-05T22:03:53Z")

</div>

Thank you for the reply. I am using groovy scripts now. I wasn't sure why script fields won't show up. Now I understand. I think script fields can't be referenced in elastic search query aggregations. That rules out the Kibana use case mentioned in my question.

---

<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:37pm UTC](https://discuss.elastic.co/t/script-fields-in-query-not-showing-up-in-kibana-visualize-aggregation/61971/4 "2017-07-06T13:37:24Z")

</div>


