# How to filter within a nested Property without change the result

**URL:** <https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425>\
**Category:** Elasticsearch\
**Created:** [November 17, 2016, 3:59pm UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425 "2016-11-17T15:59:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaTTaDox](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattadox/32/21662_2.png) [@MaTTaDox](https://discuss.elastic.co/u/MaTTaDox)\
**Post date:** [November 17, 2016, 3:59pm UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425/1 "2016-11-17T15:59:39Z")

</div>

Hey,

how can i filter within a nested Property without change the result count?

Hit Example:

```
"_index": "1000",
"_type": "example",
"_id": "1337",
"_score": 1234,
"_source": {
    "id": 1337,
    "texts": [
        {
            "name": "FooBar",
            "lang": "de",
            "referrer":1
        },
        {
            "name": "FooBar",
            "lang": "de",
            "referrer":2
        },
        {
            "name": "FooBar",
            "lang": "en",
            "referrer":1
        },

```

But I just want certain text, filter by referrer and lang for every hit without to filter any other values of the hits.

I running on version 2.3 on AWS

Thanks helping me,  
Dominik Malsch

---

<div class="post-metadata">

**Author:** ![MaTTaDox](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattadox/32/21662_2.png) [@MaTTaDox](https://discuss.elastic.co/u/MaTTaDox)\
**Post date:** [November 18, 2016, 9:11am UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425/2 "2016-11-18T09:11:25Z")

</div>

Push. Is this even possible?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 18, 2016, 9:22am UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425/3 "2016-11-18T09:22:46Z")

</div>

What does your query look like so far?

---

<div class="post-metadata">

**Author:** ![MaTTaDox](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattadox/32/21662_2.png) [@MaTTaDox](https://discuss.elastic.co/u/MaTTaDox)\
**Post date:** [November 18, 2016, 9:54am UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425/4 "2016-11-18T09:54:17Z")

</div>

I have no query so far, because i want to now this function exist.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 18, 2016, 9:58am UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425/5 "2016-11-18T09:58:13Z")

</div>

OK, got it. Then you might want to look at the [nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) type in the mapping.

Note that depending on your use-case, an alternative could be to denormalize your documents to look like:

```auto
{
    "parent_id": 1337,
    "name": "FooBar",
    "lang": "de",
    "referrer":1
}

```

And then run a [cardinality](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html) aggregation to compute the number of unique `parent_id`s.

---

<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 16, 2016, 9:58am UTC](https://discuss.elastic.co/t/how-to-filter-within-a-nested-property-without-change-the-result/66425/6 "2016-12-16T09:58:15Z")

</div>

Closed on December 16, 2016, 9:58am UTC

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