title: elastic search Nested query filter based on date is not returning correct results
body: <p>I have nested query where in i am filtering the present days data and later aggregating the data using date-histogram aggregation with hourly interval, but in date-histogram output it is returning the previous day's data also. is filter is not working?</p>
  
  <p>Here is my Query:</p>
  
  <pre><code>POST finalalertbrowser/_search?size=0
  {
      "query": {
          "bool": {
              "must": [{
                  "match_phrase": {
                      "projectId.keyword": "******************************88"
                  }
              }],
              "filter": {
                  "nested": {
                      "path": "errors",
                      "query": {
                          "bool": {
                              "filter": 
                              {
                                "range": {
                                      "errors.time": {
                                          "gte": "now/d",
                                          "lte": "now"
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
      },
      "aggs": {
          "errorData": {
              "nested": {
                  "path": "errors"
              },
              "aggs": {
                  "errorMsg": {
                      "filter": {
                        "term": {
                              "errors.errMsg.keyword": "Uncaught TypeError: $.snapUpdate is not a function"
                          }
  
                      },
                      "aggs": {
                          "hourlyData": {
                              "date_histogram": {
                                  "field": "errors.time",
                                  "interval": "hour",
                                  "time_zone": "+05:30"
                              }
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>and the output of the query is:</p>
  
  <pre><code>"aggregations": {
      "errorData": {
        "doc_count": 89644,
        "errorMsg": {
          "doc_count": 1861,
          "hourlyData": {
            "buckets": [
              {
                "key_as_string": "2018-03-13T11:00:00.000+05:30",
                "key": 1520919000000,
                "doc_count": 3
              },
              {
                "key_as_string": "2018-03-13T12:00:00.000+05:30",
                "key": 1520922600000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-13T13:00:00.000+05:30",
                "key": 1520926200000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-13T14:00:00.000+05:30",
                "key": 1520929800000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-13T15:00:00.000+05:30",
                "key": 1520933400000,
                "doc_count": 4
              },
              {
                "key_as_string": "2018-03-13T16:00:00.000+05:30",
                "key": 1520937000000,
                "doc_count": 8
              },
              {
                "key_as_string": "2018-03-13T17:00:00.000+05:30",
                "key": 1520940600000,
                "doc_count": 6
              },
              {
                "key_as_string": "2018-03-13T18:00:00.000+05:30",
                "key": 1520944200000,
                "doc_count": 3
              },
              {
                "key_as_string": "2018-03-13T19:00:00.000+05:30",
                "key": 1520947800000,
                "doc_count": 1
              },
              {
                "key_as_string": "2018-03-13T20:00:00.000+05:30",
                "key": 1520951400000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-13T21:00:00.000+05:30",
                "key": 1520955000000,
                "doc_count": 4
              },
              {
                "key_as_string": "2018-03-13T22:00:00.000+05:30",
                "key": 1520958600000,
                "doc_count": 3
              },
              {
                "key_as_string": "2018-03-13T23:00:00.000+05:30",
                "key": 1520962200000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-14T00:00:00.000+05:30",
                "key": 1520965800000,
                "doc_count": 1
              },
              {
                "key_as_string": "2018-03-14T01:00:00.000+05:30",
                "key": 1520969400000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-14T02:00:00.000+05:30",
                "key": 1520973000000,
                "doc_count": 1
              },
              {
                "key_as_string": "2018-03-14T03:00:00.000+05:30",
                "key": 1520976600000,
                "doc_count": 1
              },
              {
                "key_as_string": "2018-03-14T04:00:00.000+05:30",
                "key": 1520980200000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-14T05:00:00.000+05:30",
                "key": 1520983800000,
                "doc_count": 2
              },
              {
                "key_as_string": "2018-03-14T11:00:00.000+05:30",
                "key": 1521005400000,
                "doc_count": 349
              },
              {
                "key_as_string": "2018-03-14T12:00:00.000+05:30",
                "key": 1521009000000,
                "doc_count": 300
              },
              {
                "key_as_string": "2018-03-14T13:00:00.000+05:30",
                "key": 1521012600000,
                "doc_count": 258
              },
              {
                "key_as_string": "2018-03-14T14:00:00.000+05:30",
                "key": 1521016200000,
                "doc_count": 247
              },
              {
                "key_as_string": "2018-03-14T15:00:00.000+05:30",
                "key": 1521019800000,
                "doc_count": 144
              },
              {
                "key_as_string": "2018-03-14T16:00:00.000+05:30",
                "key": 1521023400000,
                "doc_count": 63
              },
              {
                "key_as_string": "2018-03-14T17:00:00.000+05:30",
                "key": 1521027000000,
                "doc_count": 30
              }
            ]
          }
        }
      }
    }
  </code></pre>
  
  <p>i have executed the query on 14th march 2018 , but query is giving output from 13 March 2018.</p>
  
  <p>Below is the mapping command : </p>
  
  <pre><code>PUT myIndexName
  {
   "mappings": {
  "webbrowsererror": {
       "properties": {
         "errors": {
           "type": "nested" ,
           "properties": {
             "time":{"type":"date"}
             }
         }
       }
     }
  }
  }
  </code></pre>
  
  <p><strong>and below are the sample records in the index:</strong></p>
  
  <pre><code>_source": {
            "projectId": "******************",
            "sId": "bt82x3g8v1505001600027",
            "pId": "bt82x3g8v1505001600027.1",
            "pageURL": "***************************",
            "startTime": 1505001600027,
            "country": "unknown",
            "size": 2,
            "errors": [
              {
                "sid": "bt82x3g8v1505001600027",
                "pid": "bt82x3g8v1505001600027.1",
                "browser": "Googlebot",
                "time": 1505001600028,
                "errMsg": "Uncaught SyntaxError: Invalid regular expression: missing /",
                "url": "********************************",
                "lineNo": 161,
                "colNo": 54
              },
              {
                "sid": "bt82x3g8v1505001600027",
                "pid": "bt82x3g8v1505001600027.1",
                "browser": "Googlebot",
                "time": 1505001600058,
                "errMsg": "Uncaught Error: Syntax error, unrecognized expression: #!",
                "url": "************************************************************",
                "lineNo": 3,
                "colNo": 69
              }
            ]
          }
  
  
  
  
   "_source": {
            "projectId": "shaan-shaanstack-1-1517388493060",
            "sId": "bt82x3g8v1502496000027",
            "pId": "bt82x3g8v1502496000027.1",
            "startTime": 1502496000027,
            "country": "US",
            "size": 1,
            "errors": [
              {
                "sid": "bt82x3g8v1502496000027",
                "pid": "bt82x3g8v1502496000027.1",
                "browser": "Chrome Mobile",
                "time": 1502496000128,
                "errMsg": "Uncaught Error: Syntax error, unrecognized expression: #!",
                "url": "**************************************************",
                "lineNo": 2,
                "colNo": 69
              }
            ]
          }
  
  
  
  
  
  "_source": {
            "projectId": null,
            "sId": "888888888888888",
            "pId": "bt82x3g8v1505001600027.1",
            "pageURL": "******************",
            "startTime": 1505001600027,
            "country": "unknown",
            "size": 2,
            "errors": [
              {
                "sid": "bt82x3g8v1505001600027",
                "pid": "bt82x3g8v1505001600027.1",
                "browser": "Googlebot",
                "time": 1505001600028,
                "errMsg": "Uncaught SyntaxError: Invalid regular expression: missing /",
                "url": "***********************************",
                "lineNo": 170,
                "colNo": 54
              },
              {
                "sid": "bt82x3g8v1505001600027",
                "pid": "bt82x3g8v1505001600027.1",
                "browser": "Googlebot",
                "time": 1505001600082,
                "errMsg": "Uncaught Error: Syntax error, unrecognized expression: #!",
                "url": "***********************************",
                "lineNo": 3,
                "colNo": 69
              }
            ]
          }
  </code></pre>