# Match on nested field is not working

**URL:** <https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712>\
**Category:** Elasticsearch\
**Created:** [July 3, 2019, 12:54pm UTC](https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712 "2019-07-03T12:54:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yogesh\_BG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_bg/32/70018_2.png) [@Yogesh\_BG](https://discuss.elastic.co/u/Yogesh_BG)\
**Post date:** [July 3, 2019, 12:54pm UTC](https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712/1 "2019-07-03T12:54:14Z")

</div>

Hi

I am using ES 6.4

I have a nested object with example as below

```
{
  "docs": {
    "Flwkt2sBvcxxWw1qkfxk": {
  "o_oper_state": "active",
  "p_ver": "v1",
  "h_ver": "v1",
  "stats_list": [
    {
      "app": "ubuntu",
      "conns": 2,
      "bytes": 12384,
      "rule": "rule1",
      "category": "web, analytics-and-statistics, web-ext-web-service"
    },
    {
      "app": "google_gen",
      "conns": 110,
      "bytes": 6477402,
      "rule": "rule1",
      "category": "web, web-ext-software"
    },
    {
      "app": "google_play",
      "conns": 2,
      "bytes": 181747,
      "rule": "rule1",
      "category": "mobile"
    },
    {
      "app": "google_tags",
      "conns": 2,
      "bytes": 6415,
      "rule": "rule1",
      "category": "web, web-ext-computer-and-internet-info"
    },
    {
      "app": "gstatic",
      "conns": 68,
      "bytes": 5588475,
      "rule": "rule1",
      "category": "web, web-ext-web-service"
    },
    {
      "app": "https",
      "conns": 1577,
      "bytes": 111084334,
      "rule": "rule1",
      "category": "basic, web, standards-based"
    }
   
  ],
  "ts": 1562145722626
}
  }
}

```

and mapping is as below

```
 "stats_list": {
        "type": "nested",
        "properties": {
          "app": {
            "type": "keyword"
          },
          "bytes": {
            "type": "float"
          },
          "category": {
            "type": "keyword"
          },
          "conns": {
            "type": "float"
          },
          "rule": {
            "type": "keyword"
          }
        }
      }

```

when i try to get docs matching app as ubuntu with below query it doesnt work

```
"size": 0,
  "query": {
"bool": {
  "must": [
    {
      "term": {
        “stats_list.app”: “ubuntu”
      }
    }
  ]
}
  }
```

---

<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:** [July 4, 2019, 8:28am UTC](https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712/4 "2019-07-04T08:28:37Z")

</div>

Hey,

have you tried using a [nested query](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-nested-query.html)?

--Alex

---

<div class="post-metadata">

**Author:** ![Yogesh\_BG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_bg/32/70018_2.png) [@Yogesh\_BG](https://discuss.elastic.co/u/Yogesh_BG)\
**Post date:** [July 4, 2019, 8:35am UTC](https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712/5 "2019-07-04T08:35:24Z")

</div>

yes i did use it, but no luck. It seems this is how ES behaviour is and we need to pass this query to aggregation block also so that aggregation time also filtering happens

---

<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:** [July 4, 2019, 8:57am UTC](https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712/6 "2019-07-04T08:57:18Z")

</div>

can you create a **fully** reproducible minimal example including the nested query instead of just providing snippets and also specify the exact version of Elasticsearch including the patch release?

---

<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:** [August 1, 2019, 9:05am UTC](https://discuss.elastic.co/t/match-on-nested-field-is-not-working/188712/7 "2019-08-01T09:05:37Z")

</div>

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