# Filter Kibana for a field in doc that does not exist in all douments

**URL:** <https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810>\
**Category:** Kibana\
**Created:** [May 28, 2020, 7:50pm UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810 "2020-05-28T19:50:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjaysubramanian](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sanjaysubramanian](https://discuss.elastic.co/u/sanjaysubramanian)\
**Post date:** [May 28, 2020, 7:50pm UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810/1 "2020-05-28T19:50:53Z")

</div>

Lets say I have 5 docs in my BANDS index.

Doc [1]  
{  
"score" : 100,  
"band" : "Cream",  
"genre" : "Blues"  
}

Doc [2]  
{  
"score" : 90,  
"band" : "Beatles",  
"genre" : "Pop"  
}

Doc [3]  
{  
"score" : 99,  
"band" : "Eric Clapton",  
"genre" : "Blues"  
}

Doc [4]  
{  
"score" : 91,  
"band" : "Tungsten"  
}

Doc [5]  
{  
"score" : 91,  
"band" : "Cosmic Journey"  
}

Now I want to search (using a filter on the Kibana web console) for docs in which the field "genre" does not exist. I expect two docs in the result set. How do I do that ?

Doc [4]  
{  
"score" : 91,  
"band" : "Tungsten"  
}

Doc [5]  
{  
"score" : 91,  
"band" : "Cosmic Journey"  
}

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [May 31, 2020, 7:37pm UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810/2 "2020-05-31T19:37:25Z")

</div>

You can do that by putting an "exists" clause in the "must\_not" part of a bool query:

```auto
{ "query": {
    "bool": {
      "must": [],
      "filter": [],
      "should": [],
      "must_not": [
        {
          "exists": {
            "field": "genre"
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![sanjaysubramanian](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sanjaysubramanian](https://discuss.elastic.co/u/sanjaysubramanian)\
**Post date:** [May 31, 2020, 9:07pm UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810/3 "2020-05-31T21:07:46Z")

</div>

Thanks @flash1293 Joe Reuter  
I could send in the query you proposed via Postman to hit ElasticSearch.  
However I also tried the following in the search textbox on the Kibana Web console

`not genre:*` and that gave me the docs that do not contain the `genre` key in the doc

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 3, 2020, 7:21am UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810/4 "2020-06-03T07:21:34Z")

</div>

Hi @sanjaysubramanian,

I thought you were talking about the dev console, but it seems you mean the search bar on top of Discover/Visualize/Dashboard? If it is set to KQL, then `not genre:*` is indeed the right way to do this. For Lucene, you can use `_exists_:genre`

---

<div class="post-metadata">

**Author:** ![sanjaysubramanian](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sanjaysubramanian](https://discuss.elastic.co/u/sanjaysubramanian)\
**Post date:** [June 3, 2020, 1:49pm UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810/5 "2020-06-03T13:49:20Z")

</div>

@flash1293  
Hi Joe  
Apologies for the confusion. Yes the search bar on the top of Kibana Discover 🙂  
Thank you for confirming my answer  
warmly  
sanjay

---

<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 1, 2020, 1:49pm UTC](https://discuss.elastic.co/t/filter-kibana-for-a-field-in-doc-that-does-not-exist-in-all-douments/234810/6 "2020-07-01T13:49:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
