# Find Unique values of field while using match query on other field

**URL:** <https://discuss.elastic.co/t/find-unique-values-of-field-while-using-match-query-on-other-field/330037>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [April 14, 2023, 7:02pm UTC](https://discuss.elastic.co/t/find-unique-values-of-field-while-using-match-query-on-other-field/330037 "2023-04-14T19:02:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emi\_rose](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emi_rose/32/83050_2.png) [@emi\_rose](https://discuss.elastic.co/u/emi_rose)\
**Post date:** [April 14, 2023, 7:02pm UTC](https://discuss.elastic.co/t/find-unique-values-of-field-while-using-match-query-on-other-field/330037/1 "2023-04-14T19:02:34Z")

</div>

Hello,

I would like find all unique set values of field3 that roll up under a specific value of field1 and a specific value of field2.

I've tried collapsing on field3 but it gives me the error that no mapping was found for that field in order to collapse on.

I need a query that works like this, however this query just gives documents for that filter and not the distinct values for field3:

```auto
GET my_index/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "match_phrase": {
            "field1": "value1"
          }
        },
        {
          "match_phrase": {
            "field2": "value2"
          }
        },
        {
          "range": {
            "timestamp": {
              "gte": "now-4d",
              "lte": "now"
            }
          }
        }
      ]
    }
  },
  "aggs" : {
    "langs" : {
        "terms" : { "field" : "field3", "size" : 500 }
    }
  }
}

```

---

<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 12, 2023, 7:03pm UTC](https://discuss.elastic.co/t/find-unique-values-of-field-while-using-match-query-on-other-field/330037/2 "2023-05-12T19:03:27Z")

</div>

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