# Null/blank search

**URL:** <https://discuss.elastic.co/t/null-blank-search/7268>\
**Category:** Elasticsearch\
**Created:** [April 9, 2012, 11:39am UTC](https://discuss.elastic.co/t/null-blank-search/7268 "2012-04-09T11:39:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [April 9, 2012, 11:39am UTC](https://discuss.elastic.co/t/null-blank-search/7268/1 "2012-04-09T11:39:13Z")

</div>

Hi Team,

I have a query regarding null and blank ("") search. I want to get all the documents where a particular field is not blank ("") or not null. For e. g. i have field named field1, i want to get all those docs where field1 !=null or field1 !="".

I have specified keyword analyzer on field1 in mapping file and injected some data. suppose we query like following for blank values (we are looking for docs where field1=!"") -

"query" : {  
"query\_string" : {  
"query" : "- field1:""",  
"default\_operator" : "and",  
"analyzer" : "search\_analyzer",  
"allow\_leading\_wildcard" : false,  
"analyze\_wildcard" : true  
}  
}

It gives us back those docs where field1 is not blank but it also giving us back those docs too where field1 is not present i. e. field1 is null.

Please suggest is there any way in ES to form a query string which can filter for null too.

Thanks

---

<div class="post-metadata">

**Author:** ![Jan\_Fiedler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_fiedler/32/2518_2.png) [@Jan\_Fiedler](https://discuss.elastic.co/u/Jan_Fiedler)\
**Post date:** [April 9, 2012, 11:48am UTC](https://discuss.elastic.co/t/null-blank-search/7268/2 "2012-04-09T11:48:51Z")

</div>

The better approach probably is to use the 'exists' and 'missing' filters  
within a filtered query:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Monday, April 9, 2012 1:39:13 PM UTC+2, Kranti wrote:

> Hi Team,
> 
> I have a query regarding null and blank ("") search. I want to get all the  
> documents where a particular field is not blank ("") or not null. For e. g.  
> i have field named field1, i want to get all those docs where field1 !=null  
> or field1 !="".
> 
> I have specified keyword analyzer on field1 in mapping file and injected  
> some data. suppose we query like following for blank values (we are looking  
> for docs where field1=!"") -
> 
> "query" : {  
> "query\_string" : {  
> "query" : "- field1:""",  
> "default\_operator" : "and",  
> "analyzer" : "search\_analyzer",  
> "allow\_leading\_wildcard" : false,  
> "analyze\_wildcard" : true  
> }  
> }
> 
> It gives us back those docs where field1 is not blank but it also giving us  
> back those docs too where field1 is not present i. e. field1 is null.
> 
> Please suggest is there any way in ES to form a query string which can  
> filter for null too.
> 
> Thanks
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/null-blank-search-tp3896591p3896591.html](http://elasticsearch-users.115913.n3.nabble.com/null-blank-search-tp3896591p3896591.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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 6, 2017, 3:33am UTC](https://discuss.elastic.co/t/null-blank-search/7268/3 "2017-07-06T03:33:08Z")

</div>


