# Filtering nested field

**URL:** <https://discuss.elastic.co/t/filtering-nested-field/81985>\
**Category:** Elasticsearch\
**Created:** [April 11, 2017, 1:17pm UTC](https://discuss.elastic.co/t/filtering-nested-field/81985 "2017-04-11T13:17:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yarnball](https://avatars.discourse-cdn.com/v4/letter/y/b5ac83/32.png) [@yarnball](https://discuss.elastic.co/u/yarnball)\
**Post date:** [April 11, 2017, 1:17pm UTC](https://discuss.elastic.co/t/filtering-nested-field/81985/1 "2017-04-11T13:17:28Z")

</div>

Hi all,

I have read over several docs & examples, but had no success. I am on 2.4.

My nested data is`{"name":"XYZ","taglevel":"1"}`.

I want elastic search to return `name` values of `taglevel` 1. I will then setup the same for `taglevel` 2, 3 etc.

`include` will not work, as that only lets me include on the field I am returning.

I have tried countless options [such as here.](http://dpaste.com/0600TJ9) But that returned: `nested: SearchParseException[Unexpected token START_OBJECT in [inner].]`

Here is my query (which works but does not filter):

```
  "sort": [{
    "updated": "asc"
  }],
  "_source": ["title"],
  "aggs": {
    "tag.name3": {
      "filter": {},
      "aggs": {
        "inner": {
          "aggs": {
            "tag.name": {
              "terms": {
                "field": "tag.name",
                "size": 50
              }
            },
            "tag.name_count": {
              "cardinality": {
                "field": "tag.name"
              }
            }
          },
          "nested": {
            "path": "tag"
          }
        }
      }
    }
  },
  "highlight": {
    "fields": {
      "title": {}
    }
  },
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "owner.id": "1"
        }
      }
    }
  },
  "size": 100
}
```

---

<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 9, 2017, 1:20pm UTC](https://discuss.elastic.co/t/filtering-nested-field/81985/2 "2017-05-09T13:20:52Z")

</div>

Closed on May 9, 2017, 1:20pm UTC

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