| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | [[query-dsl-exists-query]]=== Exists QueryReturns documents that have at least one non-`null` value in the original field:[source,js]--------------------------------------------------GET /_search{    "query": {        "exists" : { "field" : "user" }    }}--------------------------------------------------// CONSOLEFor instance, these documents would all match the above query:[source,js]--------------------------------------------------{ "user": "jane" }{ "user": "" } <1>{ "user": "-" } <2>{ "user": ["jane"] }{ "user": ["jane", null ] } <3>--------------------------------------------------// NOTCONSOLE<1> An empty string is a non-`null` value.<2> Even though the `standard` analyzer would emit zero tokens, the original field is non-`null`.<3> At least one non-`null` value is required.These documents would *not* match the above query:[source,js]--------------------------------------------------{ "user": null }{ "user": [] } <1>{ "user": [null] } <2>{ "foo":  "bar" } <3>--------------------------------------------------// NOTCONSOLE<1> This field has no values.<2> At least one non-`null` value is required.<3> The `user` field is missing completely.[float]==== `null_value` mappingIf the field mapping includes the <<null-value,`null_value`>> settingthen explicit `null` values are replaced with the specified `null_value`.  Forinstance, if the `user` field were mapped as follows:[source,js]--------------------------------------------------PUT /example{  "mappings": {    "_doc": {      "properties": {        "user": {          "type": "keyword",          "null_value": "_null_"        }      }    }  }}--------------------------------------------------// CONSOLEthen explicit `null` values would be indexed as the string `_null_`, and thefollowing docs would match the `exists` filter:[source,js]--------------------------------------------------{ "user": null }{ "user": [null] }--------------------------------------------------// NOTCONSOLEHowever, these docs--without explicit `null` values--would still haveno values in the `user` field and thus would not match the `exists` filter:[source,js]--------------------------------------------------{ "user": [] }{ "foo": "bar" }--------------------------------------------------// NOTCONSOLE==== `missing` queryThere isn't a `missing` query. Instead use the `exists` query inside a`must_not` clause as follows:[source,js]--------------------------------------------------GET /_search{    "query": {        "bool": {            "must_not": {                "exists": {                    "field": "user"                }            }        }    }}--------------------------------------------------// CONSOLEThis query returns documents that have no value in the user field.
 |