# Filter docs by field exists not working as expected

**URL:** https://discuss.elastic.co/t/filter-docs-by-field-exists-not-working-as-expected/27532
**Category:** Elasticsearch
**Created:** [August 17, 2015, 6:18pm UTC](https://discuss.elastic.co/t/filter-docs-by-field-exists-not-working-as-expected/27532 "2015-08-17T18:18:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)
#### Post date: [August 17, 2015, 6:18pm UTC](https://discuss.elastic.co/t/filter-docs-by-field-exists-not-working-as-expected/27532/1 "2015-08-17T18:18:36Z")

</div>

The Source Example you can see below is being returned by a query on "thin". However, you can see in my query that I'm trying to filter docs using the filter exists "sbb" field. With this query, the Source Example should not be returned because it does not have an "sbb" field correct? Where I have gone wrong in my query or mapping?

**Mapping:**

```
"mappings": {
 "mymap": {
    "_all": {
       "enabled": false
    },
    "properties": {
       "sbb": {
          "type": "boolean"
       },
       "sku": {
          "type": "string",
          "analyzer": "full_name",
          "fields": {
             "exact": {
                "type": "string",
                "index": "not_analyzed"
             },
             "partial": {
                "type": "string",
                "index_analyzer": "partial_name",
                "search_analyzer": "full_name"
             }
          }
       },
       "title": {
          "type": "string",
          "analyzer": "full_name",
          "fields": {
             "partial": {
                "type": "string",
                "index_analyzer": "partial_name",
                "search_analyzer": "full_name"
             },
             "sortable": {
                "type": "string",
                "analyzer": "sortable"
             }
          }
       }
    }
 }
}

```

**Query:**

```
"query":{
    "filtered":{
      "query":{
        "bool":{
          "should":[
            {
              "match":{
                "title":{
                  "query":"thin",
                  "operator":"and",
                  "boost":5,
                  "fuzziness":"0"
                }
              }
            },
            {
              "match":{
                "title":{
                  "query":"thin",
                  "boost":2,
                  "fuzziness":"AUTO"
                }
              }
            }
          ]
        }
      },
      "filter": {
        "exists": {
          "field": "sbb"
        }
      }
    }
}

```

**Source Example:**

```
"_source": {
   "title": "Mexican Service Medal Thin Ribbon",
   "tags": [
      "EZR",
      "ISP_IGNORE_PRODUCT_TAG",
      "sbb?_w=50&h=14",
      "SBB_Awards",
      "Thin Ribbon"
   ]
}
```

---

<div class="post-metadata">

### Author: ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)
#### Post date: [August 18, 2015, 5:22pm UTC](https://discuss.elastic.co/t/filter-docs-by-field-exists-not-working-as-expected/27532/2 "2015-08-18T17:22:11Z")

</div>

Any ideas here? I changed the sbb field from boolean, to a string, and that seems to have helped a bit, but I still get results with "thin" in the title on docs where the "sbb" field does not exist. On the [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html) exists docs, it states, if the field referenced in the "exists" is "missing completely" then those docs would not be a match.

So again, what am I missing here? Why am I getting documents where the "sbb" field is missing completely?

---

<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: [July 5, 2017, 11:55pm UTC](https://discuss.elastic.co/t/filter-docs-by-field-exists-not-working-as-expected/27532/3 "2017-07-05T23:55:13Z")

</div>


