# Ingest pipeline script field math

**URL:** <https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136>\
**Category:** Kibana\
**Created:** [February 22, 2021, 11:25pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136 "2021-02-22T23:25:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [February 22, 2021, 11:25pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/1 "2021-02-22T23:25:54Z")

</div>

Hello,

I'm trying to create a ingest processor pipeline in kibana and could use some help. I'm trying to divide 2 values by each other which is the problem. Value 1 is an integer and Value 2 is a string. I'd like to get the cardinality/unique count of recurring strings before doing the division:

`ctx.average_consumption = ctx.integer / ctx.unique_count_string`

Any thoughts on how to accomplish this in Kibana?

---

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [February 23, 2021, 5:56pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/2 "2021-02-23T17:56:50Z")

</div>

Just bumping this.

---

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [February 25, 2021, 5:29pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/3 "2021-02-25T17:29:18Z")

</div>

Just bumping this

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 25, 2021, 6:40pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/4 "2021-02-25T18:40:13Z")

</div>

Hi @gentle_ghost

I am a bit unclear what you are trying to accomplish... an ingest pipeline is run on a "Per Document" basis so it will not understand / have access to aggregations across the index.. so unless that /unique count of recurring strings is part of the document that is currently being ingested you will need to take a different approach. Do you already have that field in the document?

---

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [February 25, 2021, 8:58pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/5 "2021-02-25T20:58:38Z")

</div>

Unfortunately, I'm just not sure how to accomplish this. The enhanced data table plugin would work for a computed column but is unavailable for the current version I'm on.

Essentially I'm looking for a column that is Column A/Column B where Column A = Sum Aggregation on number field and Column B = Unique Count on string field.

I'm uncertain how to populate a column or field that would contain that data.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [February 25, 2021, 9:19pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/6 "2021-02-25T21:19:40Z")

</div>

If you can provide sample data and the end result I think we can work through how to do it. Or at least determine if it's possible.

---

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [March 9, 2021, 7:54pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/7 "2021-03-09T19:54:48Z")

</div>

How would you like to have this sample data presented?

I have the field `Total_Time_In` which is the count of the duration in seconds each individual was in the room for. I need to sum this.

I have a field `unique_person` which concatenates the string fields `Name` +` Role`. Fore example Bob + HR, Bob + Accounting, Sheila + Engineer. This is where I need the unique count.

What I'm trying to do is get the average time each unique individual spent in the room.

`average_time_spent = total_time_in / unique_person`

An ingest pipeline with a script seems like where I'd want to go with this. However I can't figure out how to turn the string into a unique field for doing aggregations with.

---

<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:** [April 6, 2021, 7:55pm UTC](https://discuss.elastic.co/t/ingest-pipeline-script-field-math/265136/8 "2021-04-06T19:55:24Z")

</div>

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