# Slice size: sum specific fields for documents which are unique in another fields

**URL:** <https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016>\
**Category:** Kibana\
**Created:** [April 20, 2017, 8:55am UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016 "2017-04-20T08:55:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vasina](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@vasina](https://discuss.elastic.co/u/vasina)\
**Post date:** [April 20, 2017, 8:55am UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/1 "2017-04-20T08:55:21Z")

</div>

Hi all!

Please help me understand something about pie chart.

Can I get sum of values in specific field of documents for documents which are unique in another field (as slice size). For example, we have documents with fields "Number of apples" and "id" of person, who has these apples in his bag. We get new documents about these people with (often) unchanged number of apples several times per hour. When we choose sum of "Number of apples" as slice size, we want to count this field only once for specific person, so we want to get sum of "Number of apples" for documents which are unique in "id" field. How can we do it?

Sorry for my bad English! Hope, my question is clear.

Thanks,  
Darya

---

<div class="post-metadata">

**Author:** ![jclose](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jclose](https://discuss.elastic.co/u/jclose)\
**Post date:** [April 20, 2017, 2:32pm UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/2 "2017-04-20T14:32:50Z")

</div>

Is this not just the unique count aggregation?

---

<div class="post-metadata">

**Author:** ![vasina](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@vasina](https://discuss.elastic.co/u/vasina)\
**Post date:** [April 20, 2017, 2:55pm UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/3 "2017-04-20T14:55:18Z")

</div>

@jclose, Unique count aggregation with what field (for my example)?

---

<div class="post-metadata">

**Author:** ![jclose](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jclose](https://discuss.elastic.co/u/jclose)\
**Post date:** [April 20, 2017, 5:32pm UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/4 "2017-04-20T17:32:44Z")

</div>

This would be a unique count for the 'apples' field. Basically, each slice of the pie will correlate to X number of apples.

So if you have the following:  
ID:1 Apples:2  
ID:2 Apples:3  
ID:3 Apples:2  
ID:4 Apples:4  
ID:5 Apples:5  
ID:6 Apples:2

You would have a pie chart with 4 slices (2, 3, 4, and 5). The slice for 2-apples would be 3x as big as the other slices, as it would correlate to IDs 1,3, and 6.

---

<div class="post-metadata">

**Author:** ![vasina](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@vasina](https://discuss.elastic.co/u/vasina)\
**Post date:** [April 21, 2017, 9:18am UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/5 "2017-04-21T09:18:44Z")

</div>

Thank you, @jclose.

And can we get this result (in your answer) if we choose Count as slice size and apples as field for split slices?

I think my question is about other thing. In my example I have something like:  
DocID: 1, PersonID: 1, Apples: 2, BagColor: blue, another fields...  
DocID: 2, PersonID: 1, Apples: 2, BagColor: blue, another fields...  
DocID: 3, PersonID: 2, Apples: 3, BagColor: blue, another fields...  
DocID: 4, PersonID: 2, Apples: 3, BagColor: blue, another fields...  
DocID: 5, PersonID: 3, Apples: 2, BagColor: yellow, another fields...  
DocID: 6, PersonID: 3, Apples: 2, BagColor: yellow, another fields...  
DocID: 7, PersonID: 4, Apples: 4, BagColor: green, another fields...  
DocID: 8, PersonID: 4, Apples: 4, BagColor: green, another fields...

I build pie chart with following metrics and buckets:  
Slice size = sum of apples  
Split slices by value of BagColor

And I want to get something like  
Slice 1 about Blue Bag with size = 5 apples  
Slice 2 about Yellow Bag with size = 2  
Slice 3 about Green Bag with size = 4

So I want my sum of apples to be counted as  
Apples in doc with DocID:1 + apples in doc with DocID: 3 + apples in doc with DocID: 5 + apples in doc with DocID: 7 (unique in PersonID).

If seems that I can't get it if I choose Unique count of apples as slice size

---

<div class="post-metadata">

**Author:** ![jclose](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jclose](https://discuss.elastic.co/u/jclose)\
**Post date:** [April 21, 2017, 3:29pm UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/6 "2017-04-21T15:29:46Z")

</div>

So, on that example, you want:

Each slice to be the sum of apples for each unique PersonID?

Will the PersonID always be the same for each DocID where that person exists? So will there ever be a case where you have PersonID: 1, Apples: 2, and then another data point with PersonID: 1, Apples: 3?

---

<div class="post-metadata">

**Author:** ![vasina](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@vasina](https://discuss.elastic.co/u/vasina)\
**Post date:** [April 24, 2017, 3:34pm UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/7 "2017-04-24T15:34:57Z")

</div>

@jclose, sorry that the answer took so long!

> [@jclose](#):
>
> Will the PersonID always be the same for each DocID where that person exists?

Yes, each person has unique (the same) personID in all documents with info about him.

> [@jclose](#):
>
> So will there ever be a case where you have PersonID: 1, Apples: 2, and then another data point with PersonID: 1, Apples: 3?

Yes, apples number is something that changes over time, but because we get info about it for each person so often (several times per hour), in some documents for one person there is the same value.

> [@jclose](#):
>
> So, on that example, you want:
> 
> Each slice to be the sum of apples for each unique PersonID?

I want each slice to be the sum of apples for all unique PersonID with bag of specific colour.

> [@vasina](#):
>
> So I want my sum of apples to be counted asApples in doc with DocID:1 + apples in doc with DocID: 3 + apples in doc with DocID: 5 + apples in doc with DocID: 7 (unique in PersonID).

---

<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 22, 2017, 3:40pm UTC](https://discuss.elastic.co/t/slice-size-sum-specific-fields-for-documents-which-are-unique-in-another-fields/83016/8 "2017-05-22T15:40:51Z")

</div>

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