# Sum field based upon the unique combination of 2 others

**URL:** <https://discuss.elastic.co/t/sum-field-based-upon-the-unique-combination-of-2-others/54216>\
**Category:** Elasticsearch\
**Created:** [June 28, 2016, 10:59pm UTC](https://discuss.elastic.co/t/sum-field-based-upon-the-unique-combination-of-2-others/54216 "2016-06-28T22:59:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterb](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@peterb](https://discuss.elastic.co/u/peterb)\
**Post date:** [June 28, 2016, 10:59pm UTC](https://discuss.elastic.co/t/sum-field-based-upon-the-unique-combination-of-2-others/54216/1 "2016-06-28T22:59:09Z")

</div>

I'm searching for a way to accomplish the following:  
I've got a date histogram interval that is by "day" and i'd like to add the `parent_size` into a sum only once even if the related `associations.c` occurs many times within that date histogram interval. Ideally I'd to be able to perform this query with **any** date histogram interval using the same "sum `parent_size` once for each unique `associations.c` per day" logic.

Below is an example document in the index I'm querying against:

* * *

```
{
    "associations": {
        "a": [
            "2514519s-f379-11e3-ae2b-3176bd53680f"
        ],
        "b": [
            "5e8a07af-d2d3-4a1c-ba43-07f5cfc0eb8d"
        ],
        "c": [
            "6bda18ag-f379-11e3-ae2b-3176bd53680f"
        ]
    },
    "parent_size": 110,
    "id": "d5fe6216-7eb7-4d81-b3b2-eef28850b80d",
    "created_at": "2016-05-23T23:51:17.661Z"
}

```

* * *

---

<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:** [July 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/sum-field-based-upon-the-unique-combination-of-2-others/54216/2 "2017-07-05T22:39:49Z")

</div>

Closed on July 5, 2017, 10:39pm UTC


