# Add two fields in kibana within same Index

**URL:** <https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225>\
**Category:** Kibana\
**Created:** [November 10, 2017, 5:45pm UTC](https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225 "2017-11-10T17:45:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pathakhcst](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pathakhcst](https://discuss.elastic.co/u/pathakhcst)\
**Post date:** [November 10, 2017, 5:45pm UTC](https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225/1 "2017-11-10T17:45:42Z")

</div>

I get the multiple records from different nodes as follows:-1:  
{"name":"AAA","price":"100"}  
{"name":"BBB","price":"200"}  
{"name":"CCC","price":"400"}  
{"name":"AAA","price":"100"}  
I want to add the price of all 3 reading and show the total price in graph. Is this possible in Kibana?

---

<div class="post-metadata">

**Author:** ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)\
**Post date:** [November 10, 2017, 7:32pm UTC](https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225/2 "2017-11-10T19:32:40Z")

</div>

I think you can do this with a "top hit" aggregation with a split series on name.

 ![36 PM](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f6f95bc5f41ed34c58733dc686b6c5ae4461dda2.png)  
 ![48 PM](https://us1.discourse-cdn.com/elastic/original/3X/4/e/4e721120833273313d588f96f6ec22afaaf59deb.png)

It will only pick a single "top hit" (which I _think_ is "most recent", not "highest". I could be wrong on that but as long as you expect duplicate names to have the same price, it doesn't matter).

Here's my sample data I used that matches what you gave:

 ![15 PM](https://us1.discourse-cdn.com/elastic/original/3X/6/6/66da6aaa37db206edfb0f6e7c6fdb189178a8af8.png)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![iam.xtreme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iam.xtreme/32/20143_2.png) [@iam.xtreme](https://discuss.elastic.co/u/iam.xtreme)\
**Post date:** [November 12, 2017, 8:46am UTC](https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225/3 "2017-11-12T08:46:35Z")

</div>

You can achieve the same by creating a scripted field. Check for the detailed document here [Scripted Field Document](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

---

<div class="post-metadata">

**Author:** ![pathakhcst](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pathakhcst](https://discuss.elastic.co/u/pathakhcst)\
**Post date:** [November 27, 2017, 3:48pm UTC](https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225/4 "2017-11-27T15:48:36Z")

</div>

This helped. Thanks! Can I calculate how long(time) the AAA was 100 or 0, BBB was 200, CCC was 400? I want to calculate the price distribution in last 24 hours, 1 week, 1month.

---

<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:** [December 25, 2017, 3:48pm UTC](https://discuss.elastic.co/t/add-two-fields-in-kibana-within-same-index/107225/5 "2017-12-25T15:48:55Z")

</div>

Closed on December 25, 2017, 3:48pm UTC

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