# (ES 6.5.4) filtering by nested date field

**URL:** <https://discuss.elastic.co/t/es-6-5-4-filtering-by-nested-date-field/209747>\
**Category:** Elasticsearch\
**Created:** [November 27, 2019, 6:37pm UTC](https://discuss.elastic.co/t/es-6-5-4-filtering-by-nested-date-field/209747 "2019-11-27T18:37:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kev12123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kev12123/32/55709_2.png) [@kev12123](https://discuss.elastic.co/u/kev12123)\
**Post date:** [November 27, 2019, 6:37pm UTC](https://discuss.elastic.co/t/es-6-5-4-filtering-by-nested-date-field/209747/1 "2019-11-27T18:37:56Z")

</div>

Hi I'm relatively new ES and I've created an index with the following mapping:

```
{
  "_doc": {
    "date_detection": "false",
    "properties": {
      "@fields": {
        "properties": {
          "client": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 8191
              }
            }
          },
          "bar": {
            "type": "integer"
          },
          "foo": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 8191
              }
            }
          },
          "fooIn": {
            "type": "integer"
          },
          "missDoc": {
            "type": "nested",
            "properties": {
              "formula": {
                "type": "keyword",
                "ignore_above": 8191
              },
              "key": {
                "type": "text",
                "fields": {
                  "raw": {
                    "type": "keyword",
                    "ignore_above": 8191
                  }
                }
              },
              "isNa": {
                "type": "keyword",
                "ignore_above": 8191
              },
              "missTime": {
                "type": "date",
                "format": "yyyymmdd HH:mm:ss"
              },
              "ns": {
                "type": "keyword",
                "ignore_above": 8191
              }
            }
          },
          "fooplat": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 8191
              }
            }
          },
          "foosess": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 8191
              }
            }
          },
          "sn": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 8191
              }
            }
          }
        }
      }
    }
  }
}

```

I've written a very simple query in which the data is filtered by the @fields.missDoc.missTime which is a field in a nested type.

```
  {
  "from": 0,
  "size": 1,
  "query": {
    "bool": {
      "must": [{
        "nested": {
          "path": "@fields.missDoc",
          "query": {
            "bool": {
              "filter": [{
                "range": {
                  "@fields.missDoc.missTime": {
                    "gte": "20191109 23:58:09",
                    "lte": "20191130 23:59:59"
                  }
                }
              }]
            }
          }
        }
      }]
    }
  }
}

```

when I execute the query the data returned contains docs that are not within the specified date range. I also tried querying for a date range that is not in the index yet the query still returns data. I'd like to get some suggestions on how to correctly write this query.

---

<div class="post-metadata">

**Author:** ![kev12123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kev12123/32/55709_2.png) [@kev12123](https://discuss.elastic.co/u/kev12123)\
**Post date:** [November 27, 2019, 9:03pm UTC](https://discuss.elastic.co/t/es-6-5-4-filtering-by-nested-date-field/209747/2 "2019-11-27T21:03:50Z")

</div>

Found my issue. The date format for the missTime field was the culprit. I changed it to "yyyyMMdd HH:mm:ss" and the query worked as expected.

---

<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 25, 2019, 9:03pm UTC](https://discuss.elastic.co/t/es-6-5-4-filtering-by-nested-date-field/209747/3 "2019-12-25T21:03:59Z")

</div>

Closed on December 25, 2019, 9:03pm UTC

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