# Scripted Fields v. X-Axis

**URL:** <https://discuss.elastic.co/t/scripted-fields-v-x-axis/177555>\
**Category:** Kibana\
**Created:** [April 19, 2019, 1:53am UTC](https://discuss.elastic.co/t/scripted-fields-v-x-axis/177555 "2019-04-19T01:53:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvisz-inf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dvisz-inf/32/42617_2.png) [@dvisz-inf](https://discuss.elastic.co/u/dvisz-inf)\
**Post date:** [April 19, 2019, 1:53am UTC](https://discuss.elastic.co/t/scripted-fields-v-x-axis/177555/1 "2019-04-19T01:53:04Z")

</div>

Hi,

I have an index with some bad data in a `date` field. Where `epoch_second` was expected, `epoch_millisecond` was indexed instead.

I added a scripted field to provide a corrected value.

I created a new Area Chart visualization.

When I try to aggregate this field for my Y axis, the field shows up in the list of valid fields.

When I try to aggregate this field for my X axis, the field does not show up.

![Screenshot%20from%202019-04-18%2018-49-18](https://us1.discourse-cdn.com/elastic/original/3X/3/8/3837e7eb51ee3c980342fbaa8dad90c007d8b45d.png)

![Screenshot%20from%202019-04-18%2018-51-18](https://us1.discourse-cdn.com/elastic/original/3X/8/4/847028e47c73dad49a0903d27cd8a5e1ea5b019d.png)

Is there any way around this? It will be a while before I can fix this field and would like to know how to improvise in a situation like this.

My Kibana is version 6.5.3.

Thanks!

---

<div class="post-metadata">

**Author:** ![joshdover](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshdover/32/42020_2.png) [@joshdover](https://discuss.elastic.co/u/joshdover)\
**Post date:** [April 19, 2019, 9:44pm UTC](https://discuss.elastic.co/t/scripted-fields-v-x-axis/177555/2 "2019-04-19T21:44:39Z")

</div>

Unfortunately, scripted fields cannot be used in the X-Axis because the X-Axis is what is being filtered on and scripted fields cannot be used for filtering/searching.

I would suggest using your scripted field script with the [Update By Query API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) to fix your documents. With this API you can modify the documents using a painless script (should be similar to your scripted field). Keep in mind, that any new data being ingested will need to be updated as well. You can do this either at the source, or by using an Ingest Pipeline to cleanup data.

---

<div class="post-metadata">

**Author:** ![dvisz-inf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dvisz-inf/32/42617_2.png) [@dvisz-inf](https://discuss.elastic.co/u/dvisz-inf)\
**Post date:** [April 23, 2019, 12:05am UTC](https://discuss.elastic.co/t/scripted-fields-v-x-axis/177555/3 "2019-04-23T00:05:43Z")

</div>

@joshdover `_update_by_query` to fix this field is something I'm planning on.

In SQL I would be able to `select floor(x/1000) as x from t group by x` which would aggregate on the field as it has been indexed but then return a "fixed" value for `x`. I suppose there is no way to do this for Kibana?

Thanks!

---

<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:** [May 21, 2019, 12:05am UTC](https://discuss.elastic.co/t/scripted-fields-v-x-axis/177555/4 "2019-05-21T00:05:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
