# X/y shards failed in data table visualization when applying aggregation on scripted fields

**URL:** <https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507>\
**Category:** Kibana\
**Created:** [December 19, 2018, 12:07pm UTC](https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507 "2018-12-19T12:07:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shripal](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@Shripal](https://discuss.elastic.co/u/Shripal)\
**Post date:** [December 19, 2018, 12:07pm UTC](https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507/1 "2018-12-19T12:07:37Z")

</div>

I am using a data table visualization to show data. I used the count metric, along with 7 sub-buckets that are all aggregations of the type 'Terms'. Two fields out of the 7 on which aggregation is applied are scripted fields. When I run this over a month's time period, Error stating 'x/y shards failed', or 'Error creating visualization, Request timeout.'

All the 7 fields are absolutely necessary to be shown in this data table. If I remove one scripted field, this works fine. But if I add the aggregation on that field again, it crashes. Can you please help with this?

![2018-12-19_17h35_32](https://us1.discourse-cdn.com/elastic/original/3X/2/7/27749ee602dfd8311d367c90086ff5d2e33eb5d1.png)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 19, 2018, 12:33pm UTC](https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507/2 "2018-12-19T12:33:50Z")

</div>

Does all documents contain the fields used to calculate the scripted fields? Do you check to verify that the fields exist before using them so you can provide a default value in case they do not exist?

---

<div class="post-metadata">

**Author:** ![Shripal](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@Shripal](https://discuss.elastic.co/u/Shripal)\
**Post date:** [December 20, 2018, 12:27pm UTC](https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507/3 "2018-12-20T12:27:19Z")

</div>

Yes Christian, all the documents contain the scripted field.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 20, 2018, 12:38pm UTC](https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507/4 "2018-12-20T12:38:07Z")

</div>

That is not exactly what I asked. Let me rephrase. Does all the documents contain all the fields used in the calculation of the scripted field? Does the definition of your scripted field check for existence?

Can you show an example of a scripted field definition?

---

<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:** [January 17, 2019, 12:48pm UTC](https://discuss.elastic.co/t/x-y-shards-failed-in-data-table-visualization-when-applying-aggregation-on-scripted-fields/161507/5 "2019-01-17T12:48:11Z")

</div>

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