# Having ElasticSearch ignore filter when field does not exist

**URL:** https://discuss.elastic.co/t/having-elasticsearch-ignore-filter-when-field-does-not-exist/35920
**Category:** Elasticsearch
**Created:** [November 30, 2015, 3:27pm UTC](https://discuss.elastic.co/t/having-elasticsearch-ignore-filter-when-field-does-not-exist/35920 "2015-11-30T15:27:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![thiagolocatelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiagolocatelli/32/6424_2.png) [@thiagolocatelli](https://discuss.elastic.co/u/thiagolocatelli)
#### Post date: [November 30, 2015, 3:27pm UTC](https://discuss.elastic.co/t/having-elasticsearch-ignore-filter-when-field-does-not-exist/35920/1 "2015-11-30T15:27:44Z")

</div>

Hi all,

I am running a query against an alias that is currently pointing to a dozen of indexes. Not all documents have the same structure across these indexes, so I am trying to run a filtered query:

```
GET /thiago/_search
  {
  "query" : {
     "filtered" : { 
           "filter" : {
              "bool" : {
                "should" : { 
                    "term" : { "channel" : "24" }
                 }
             }
           }
        }
     }
  }

```

ElasticSearch is filtering all documents that have channel 24, but I would also want all the other document that do not have the attribute channel. For example, my query should bring all actors (doc doesnt have property channel), movies (doc doesnt have property channel), genres (doc doesnt have property channel) and tv shows (doc has property channel) that air on channel 24.

Is there a way to do that without involving filter script?

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [November 30, 2015, 5:51pm UTC](https://discuss.elastic.co/t/having-elasticsearch-ignore-filter-when-field-does-not-exist/35920/2 "2015-11-30T17:51:33Z")

</div>

Maybe something like this:

```auto
GET /thiago/_search
  {
  "query" : {
     "filtered" : { 
           "filter" : {
              "bool" : {
                "should" : { 
                    "term" : { "channel" : "24" },
                    "missing": { "field": "channel" }
                 }
             }
           }
        }
     }
  }

```

---

<div class="post-metadata">

### Author: ![thiagolocatelli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiagolocatelli/32/6424_2.png) [@thiagolocatelli](https://discuss.elastic.co/u/thiagolocatelli)
#### Post date: [December 1, 2015, 2:15am UTC](https://discuss.elastic.co/t/having-elasticsearch-ignore-filter-when-field-does-not-exist/35920/3 "2015-12-01T02:15:07Z")

</div>

It works. Thank you @jpountz

---

<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:34pm UTC](https://discuss.elastic.co/t/having-elasticsearch-ignore-filter-when-field-does-not-exist/35920/4 "2017-07-05T23:34:40Z")

</div>


