# Filter/Collapse on multiple fields

**URL:** <https://discuss.elastic.co/t/filter-collapse-on-multiple-fields/252858>\
**Category:** Elasticsearch\
**Created:** [October 21, 2020, 2:51pm UTC](https://discuss.elastic.co/t/filter-collapse-on-multiple-fields/252858 "2020-10-21T14:51:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Turbo-555](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/turbo-555/32/77609_2.png) [@Turbo-555](https://discuss.elastic.co/u/Turbo-555)\
**Post date:** [October 21, 2020, 2:51pm UTC](https://discuss.elastic.co/t/filter-collapse-on-multiple-fields/252858/1 "2020-10-21T14:51:36Z")

</div>

Hi all,

I'm trying to find documents that have distinct values over 2 separate fields.  
Documents have \_id, filters.10,filters.20

For Example:

```auto
    1, f10_1, f20_1
    2, f10_1, f20_1
    3, f10_2, f20_1
    4, f10_3, f20_2

```

what I'm trying to find is:

```auto
    1, f10_1, f20_1
    4, f10_3, f20_2

```

2 documents that have bot filters.10 and filters.20 distinct

collapse only works on one field...

I tried:

```auto
{
  "size":3,
  "aggs": {
    "uniq_10": {
    "terms": {
        "script": "doc['filters.10'].value+doc['filters.20'].value",
      }
    }
  }
}

```

but it doesn't do what I need ☹

any tips are welcome

Thanks

---

<div class="post-metadata">

**Author:** ![Turbo-555](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/turbo-555/32/77609_2.png) [@Turbo-555](https://discuss.elastic.co/u/Turbo-555)\
**Post date:** [October 23, 2020, 5:32am UTC](https://discuss.elastic.co/t/filter-collapse-on-multiple-fields/252858/2 "2020-10-23T05:32:48Z")

</div>

just for clarification, filters.10 and filters.20 are the field names:

```auto
ID,filters.10,filters.20
1 , f10_1 , f20_1
2 , f10_1 , f20_1
3 , f10_2 , f20_1
4 , f10_3 , f20_2

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 26, 2020, 9:22am UTC](https://discuss.elastic.co/t/filter-collapse-on-multiple-fields/252858/3 "2020-10-26T09:22:01Z")

</div>

instead of using your shortened syntax a fully reproducible example including index creation/mapping, document creation and query might help **a lot** here for others to create a proper context.

Thank you!

---

<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:** [November 23, 2020, 9:22am UTC](https://discuss.elastic.co/t/filter-collapse-on-multiple-fields/252858/4 "2020-11-23T09:22:06Z")

</div>

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