# Average number of fields per another field

**URL:** <https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872>\
**Category:** Kibana\
**Created:** [May 15, 2018, 7:35am UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872 "2018-05-15T07:35:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pardha\_Saradhi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pardha_saradhi/32/75048_2.png) [@Pardha\_Saradhi](https://discuss.elastic.co/u/Pardha_Saradhi)\
**Post date:** [May 15, 2018, 7:35am UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872/1 "2018-05-15T07:35:38Z")

</div>

I have two fields in elastic search document, item\_id, package\_id, and creation\_time. They are in a one to may relationship ( 1 item\_id -\> many package\_id)

I want to display the (number of unique package\_id/ unique number of item\_id) in buckets based on creation\_time.

Is this possible in kibana (version 5.5.1)? I am able to get the unique count of item\_id and unique count of package\_id and split them into buckets. I have no idea how to divide them (items/packages). Please help.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [May 15, 2018, 4:44pm UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872/2 "2018-05-15T16:44:12Z")

</div>

Sounds like the easiest thing here might be to create a scripted field that combines them, then do a unique count based on that.

Something like:

```auto
doc['item_id.raw'].value + '|' + doc['package_id.raw'].value

```

---

<div class="post-metadata">

**Author:** ![Pardha\_Saradhi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pardha_saradhi/32/75048_2.png) [@Pardha\_Saradhi](https://discuss.elastic.co/u/Pardha_Saradhi)\
**Post date:** [May 16, 2018, 10:47am UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872/3 "2018-05-16T10:47:27Z")

</div>

Created a scripted filed like you mentioned. But it is not visible in the drop down of Time series builder when I select cardinality.  
Is this because item\_id is a integer and package\_id is a string?

---

<div class="post-metadata">

**Author:** ![lfroment-datasweet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lfroment-datasweet/32/32908_2.png) [@lfroment-datasweet](https://discuss.elastic.co/u/lfroment-datasweet)\
**Post date:** [May 16, 2018, 4:16pm UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872/4 "2018-05-16T16:16:58Z")

</div>

Hi, we recently released a Kibana plugin that should do the job. Check it out there [https://github.com/datasweet-fr/kibana-datasweet-formula](https://github.com/datasweet-fr/kibana-datasweet-formula)

Compatible with 5.6 and upward.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [May 16, 2018, 4:17pm UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872/5 "2018-05-16T16:17:41Z")

</div>

Ahh, unfortunately TSVB doesn't support scripted fields ☹

Could you index this field instead?

---

<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:** [June 13, 2018, 4:17pm UTC](https://discuss.elastic.co/t/average-number-of-fields-per-another-field/131872/6 "2018-06-13T16:17:52Z")

</div>

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