title: ElasticSearch query doesn't return documents that have an "empty" nested property
body: <p>I'm running into a weird problem. I have a document mapping for which one of the properties is a nested object. </p>
  
  <pre><code>{
      "userLog": {
          "properties": {
              "userInfo": {
                  "userId": {
                      "type": "text"
                  },
                  "firstName": {
                      "type": "text"
                  },
                  "lastName": {
                      "type": "text"
                  },
                  "email": {
                      "type": "text"
                  }
              },
              "violations": {
                  "type": "integer"
              },
              "malfunctions": {
                  "type": "integer"
              },
              "extensionsUsed": {
                  "type": "integer"
              },
              "date": {
                  "type": "date",
                  "format": "yyyy-MM-dd||yyyy/MM/dd||yyyyMMdd||epoch_millis"
              },
              "events": {
                  "type": "nested",
                  "properties": {
                      "editorId": {
                          "type": "text"
                      },
                      "editorRole": {
                          "type": "text"
                      },
                      "editedTimestamp": {
                          "type": "date",
                          "format": "epoch_millis"
                      },
                      "createdTimestamp": {
                          "type": "date",
                          "format": "epoch_millis"
                      },
                      "userId": {
                          "type": "text"
                      },
                      "timestamp": {
                          "type": "date",
                          "format": "epoch_millis"
                      },
                      "eventType": {
                          "type": "text"
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Some userLogs have events and some don't. My queries only return userLogs that have events, however, and I'm not sure why. There are definitely userLogs that exist without events in the index. I can see them in Kibana. They just aren't returned in the search. Here's what I'm running for a query:</p>
  
  <pre><code>GET index_name/_search
  {
    "query": {
      "bool": {
        "must": [
          {
            "range": {
              "date": {
                "gte": "20170913",
                "format": "yyyyMMdd"
              }
            }
          }
        ],
        "should": [
          {
            "match_phrase": {
              "userInfo.userId": "Xvo9qblajOVaM3bQQMaV4GKk7S42"
            }
          }
        ],
        "minimum_number_should_match": 1
      }
    }
  }
  </code></pre>
  
  <p>based on <a href="https://github.com/elastic/elasticsearch/issues/3495" rel="nofollow noreferrer">this discussion</a></p>
  
  <p>I modified my query to be the following: </p>
  
  <pre><code>GET one20_eld_portal/_search
  {
      "query": {
      "bool": {
        "must_not": [
          {
            "nested": {
              "path": "events",
              "query": {
                "bool": {
                  "filter": {
                    "exists": {
                      "field": "events.userId"
                    }
                  }
                }
              }
            }
          }
        ],
          "should": [
            {
              "match_phrase": {
                "userInfo.uid": "Xvo9qblajOVaM3bQQMaV4GKk7S42"
              }
            }
          ],
          "minimum_should_match": 1
        }
    }
  }
  </code></pre>
  
  <p>but this doesn't return <em>any</em> results. Any help is greatly appreciated!</p>